PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Object Initialization

While you can always override the action controller's constructor, we do not recommend this. Zend_Controller_Action::__construct() performs some important tasks, such as registering the request and response objects, as well as any custom invocation arguments passed in from the front controller. If you must override the constructor, be sure to call parent::__construct($request, $response, $invokeArgs).

The more appropriate way to customize instantiation is to use the init() method, which is called as the last task of __construct(). For example, if you want to connect to a database at instantiation:

<?php
class FooController extends Zend_Controller_Action
{
    public function 
init()
    {
        
$this->db Zend_Db::factory('Pdo_Mysql', array(
            
'host'     => 'myhost',
            
'username' => 'user',
            
'password' => 'XXXXXXX',
            
'dbname'   => 'website'
        
));
    }
}

Zend Framework