ZF controller init method

[cc lang=”php” tab_size=”2″ lines=”40″]public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
{
$this->setRequest($request)
->setResponse($response)
->_setInvokeArgs($invokeArgs);
$this->_helper = new Zend_Controller_Action_HelperBroker($this);
$this->init();
}[/cc]

在zf 每個 controller 中
可以用function init 這個去代替__constructor (不知道這樣形容 恰不恰當)

Whenever Zend Framework instantiates a controller, the base Zend Framework class (in our case Zend_Controller_Action) has a lot of important code in the __construct() method.  It is possible to override the __construct() in your controller but it is not recommended. Instead, Zend Framework gives us the init() method. init() is the last thing called in __construct() and it is the appropriate place for us to put anything we want executed upon construction.

發佈留言

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料