php - Zend Framework: What are the differences between init() and preDispatch() functions in controller objects? -


I think the order of execution is init (), preDispatch () and then the verb () is called.

  1. Should I initialize my variable, which is common in all functions, init () or preDispatch ()? I have seen people using both functions for initialization, probably as the name indicates that it should be done init (), but what type of content will be in predispatch ()?

  2. What is the function call between init () and preDispatch ()?

ago preDispatch () to < Code is called for example> Zend_Controller_Plugin_Abstract . Here you have the request and feedback object, so you can make the filter or some preparation using the information from the request.

Init () 's Zend_Controller_Action has been given the name as part of the constructor. The signature of the constructor ( Zend_Controller_Action :: __contract () ) is to assist you in initializing your controller without overriding and repeating.

Controller's preDispatch) The method here is called $ request-> to leave the current code. Set despatched (incorrect) - Not sure that you can do this init ()

Then your action method (for example, ViewAction () ).

The difference now should be clear:

  • If you want to execute something before you, then all actions - keep it in plug-in and use a hook (< In addition to code> preDispatch () there routeStartup more),
  • if you want to first ,
  • if only one The only action - to take action - is the only action.
  • > > init or preDispatch () Ul>

    init () and What happens between preDispatch () function call?

    Almost nothing - Pre Dispatch () is executed, and if you have $ request-> If set is not specified (wrong) , then the action is executed.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -