I was working on an application where I needed all unique brands from a mysql table to populate a HTML select box. I have no idea how to do that quickly with Zend_Table, so I found out you can just pass on your own SQL if you want.
A simple “SELECT DISTINCT brand FROM products ORDER BY brand ASC” will do in these cases. It would even be better if I had a seperate brands table, so I wouldn’t have this problem at all. But since this was a quick and dirty job, there was no brands table ;)
Anyway, these lines will do the job (where $db is an instance of your Db adapter):
$statement = $db->query('SELECT DISTINCT brand FROM products ORDER BY brand ASC');
$this->view->brands = $statement->fetchAll();
Use foreach() in your view to display the list:
echo ' ';
And that’s it!
Ik zat vandaag met het volgende probleem:
Oplossing:
In principe is een view helper gewoon een class. Een class kun je gewoon aanroepen en uitvoeren vanuit bijvoorbeeld de view helper “showMenu”:
Zend_Loader::loadClass('Sterc_View_Helper_MakeUrl');
$url = new Sterc_View_Helper_MakeUrl();
$link = $url->makeUrl($linkId, 'page');
Kleine kanttekening hierbij is: De view helper staat dus hier: ‘/library/Sterc/View/Helper/MakeUrl.php’.
Zo simpel is het dus: 3 regels code, in plaats van de hele functie makeUrl in bijvoorbeeld de view helper ShowMenu te plakken.
Textmate is mijn meest gebruikte editor, sinds ik een Macbook heb. Sinds gisteren gebruik ik nu ook mijn zelfgemaakte theme. Je kan hem hier bekijken.
Het thema is geschikt voor PHP, HTML (met PHP) en JavaScript en zal ongetwijfeld worden gewijzigd om beter te werken met Zend Framework en jQuery, omdat ik dat dagelijks gebruik.
I developed my own Textmate theme. It’s suitable for PHP, HTML, JavaScript and jQuery. Down below are some screenshots of my theme in action.
Textmate is a text editor for OSX. If you don’t have OSX and use Windows instead, you can use e-texteditor. e is a third-party port of Textmate. My theme works on e too.
PHP

HTML (met PHP)

JavaScript (jQuery in this case)

Click on the button below to download the theme. Simply open it and it will be usable inside Textmate.
Het maakt mij in ieder geval wel happy! Slagsmålsklubben is een Zweedse ‘band’ die hele grappige muziek maakt. Het zou zo maar kunnen dat je deze muziek terug hoort in een The Sims spel of een tekenfilm of iets dergelijks. Luister maar eens naar hun muziek op hun myspace. Hier op kantoor bij Sterc zijn we in ieder geval helemaal hooked!