Dispatch in controller is a special event that execute before or after each action method call.
Dispatch Method
There are two type of dispatch method.
1.Pre-Dispatch
2.Post Dispatch
Pre Dispatch
Pre dispatch method runs before Action Method call. See below example:
public function __preDispatch()
{
}
Post Dispatch
Pre dispatch method runs after Action Method call. See below example:
public function __postDispatch()
{
}
Note: No action will happened if we do not create dispatch method
We can do common work in dispatch function to apply it for all Action Method in same controller.
Dispatch Method
Dispatch Variable used to exclude any Action Method to run pre Dispatch functions. below are variables:
public $dispatch = Array(
'preDispatchExclude' => array(),
'postDispatchExclude' => array()
);
For example:
/* Exclude Home page */
public $dispatch = Array(
'preDispatchExclude' => array('indexAction'),
'postDispatchExclude' => array()
);