Accessing controller data from a partial viewscript
When using an inline partial viewscript in my form, I sometimes need access to data. I can accomplish this by using a setter and getter with a public function in my form. We’ll use the action “guinness” as the controller action in this example. application\modules\project\forms\guinness\base.php protected $_id; public function setId($id) { $this->_id = $id; return [...]
SVN Externals – how to add them
When creating a Zend Framework site, its always best to keep the Zend library as an external source. This way you can keep the branch up-to-date with the release of Zend with a simple text file. To access the externals file, navigate to the root of your site: > cd /var/www/mysite And add the external [...]
How to pass data from Controller to Zend Form
To pass data from your controller, to a Zend_Form, you can utilise the config parameters: $this->view->form = new Contact_Edit_Form(array(‘contactName’ => ‘Chris’)); This will pass a very simple array to the form, and from within the form, $data = $this->getAttrib(‘contactName’); $data will then contain Chris
Zend Console – get values passed
When using a CLI script with options, I like to use the Zend_Console. If my options are as follows: $console = new Zend_Console_Getopt( array( ‘i-s’ => ‘test option 1′, ‘e’ => ‘test option 2′) ); For instance, > php myScript.php -i OPTION To get the “OPTION” string for the -i parameter $arg = $console->getOption(‘i’); $arg [...]
Zend_Date – difference between 2 dates
I keep having trouble with this simple calculation! So, here is a little example to get the amount of days between now and the next occurance of July 1st. //set up the 2 date objects $now = new Zend_Date(); $next = new Zend_Date(); //we want July 1st $next->setDay(1)->setMonth(7); //if we are currently after july this [...]
Accessing the Zend_Application from a page
If, like me, you need to access some Zend_Application resources (such as multidb resources) – then you need a reference to the Zend_Application and the bootstrap. I use this: if (null == $this->_application) { $this->_application = Zend_Controller_Front::getInstance() ->getParam(‘bootstrap’); }