Zend Caveats
Ever gets frustrated during your coding? I’m pretty sure the answer is a big YES especially if you’re new with the programming language you’re trying to develop or you might have forgotten the old programming language you used to. Likewise, most of the time we get frustrated when there is a stumbling block during your development especially when the deadline is imminent. The expression “Argh!!” or banging on a table are common to convey the frustration. :)
Anyway, here I’m going to share with some of my encounters that I can still recall during my past development using Zend Framework.
Controller
$this->_forward()somehow reset protected variables upon two consecutive executions. Unfortunately I am unable to recall the exact situation during the encounter.- Avoid using
Zend_Form_Element_Submit->setAttrib('value','submit')but rather to useZend_Form_Element_Submit->setValue(). $this->url( array( 'controler' => 'control', 'action' => 'action' ))will only set or replace the specified parameters and retain other parameters of the current url. In this example, the function will only set the controller name and action name with ‘control’ and ‘action’ respectively. Thus if there’s additional parameter in the url, say id, then the id and its value will be retained in the new url.- If your code needs to access variable(s) within a Controller, then put your code within an override function preDispatch() instead of init(). Function init() does not allow your code to access the desired variable within the Controller.
Database
- To order your query result, use
$select->order()instead of$select->fetch($query, $order). - Use
$db->select()->setIntegrityCheck(false)if you encounter the following error message.
Multiple SQL statements are not allowed (SELECT ...; DELETE..;) $db->select()->join() Exception information: Message: Select query cannot join with another table
You may refer to this site for more information.
Hope this post helps settle down your unhealthy frustration. Enjoy! :)
Don't leave just yet! You may also be interested to take a quick look at my other posts.
