开发者

Which happens first: init or preDispatch?

开发者 https://www.devze.com 2023-01-17 04:16 出处:网络
I was reading the answer to the question here and the wording was a bit confusing. I shortened 开发者_StackOverflow中文版the sentences to focus on my question

I was reading the answer to the question here and the wording was a bit confusing. I shortened 开发者_StackOverflow中文版the sentences to focus on my question

  • First preDispatch() is called for instances of Zend_Controller_Plugin_Abstract...
  • init() of the Zend_Controller_Action is called next...
  • The controller's preDispatch() method is called here...

Does that mean that in the controller itself, init code runs first before the preDispatch code?

There's a preDispatch that runs first but it's not for controller code, just for code that may exist in any outside plugins, correct?


Indeed, the init runs before preDispatch. A complete flow of events is visualized in this diagram:

Which happens first: init or preDispatch?

For me it was very useful to understand the complete Zend Framework frontcontroller structure.


init runs before preDispatch, init is short for initialisation (or initialization if you're American).

So it runs first to initialisation anything you might need later in the Controller


Just add an init() method to your own action helper, which hooks into your controller init(), either way you can utilize the init() before preDispatch().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号