Dispatching is the process of taking the request object,
Zend_Controller_Request_Abstract, extracting the module
name, controller name, action name, and optional parameters
contained in it, and then instantiating a controller and calling an
action of that controller. If any of the module, controller, or
action are not found, it will use default values for them.
Zend_Controller_Dispatcher_Standard specifies
index for each of the controller and action defaults
and default for the module default value, but allows
the developer to change the default values for each using the
setDefaultController(),
setDefaultAction(), and
setDefaultModule() methods, respectively.
Default Module
When creating modular applications, you may find that you want
your default module namespaced as well (the default
configuration is that the default module is
not namespaced). As of 1.5.0, you can now
do so by specifying the prefixDefaultModule as
TRUE in either the front controller or your dispatcher:
<?php
// In your front controller:
$front->setParam('prefixDefaultModule', true);
// In your dispatcher:
$dispatcher->setParam('prefixDefaultModule', true);
This allows you to re-purpose an existing module to be the default module for an application.
Dispatching happens in a loop in the front controller. Before dispatching occurs, the front controller routes the request to find user specified values for the module, controller, action, and optional parameters. It then enters a dispatch loop, dispatching the request.
At the beginning of each iteration, it sets a flag in the request object indicating that the action has been dispatched. If an action or pre or postDispatch plugin resets that flag, the dispatch loop will continue and attempt to dispatch the new request. By changing the controller and/or action in the request and resetting the dispatched flag, the developer may define a chain of requests to perform.
The action controller method that controls such dispatching is
_forward(); call this method from any of the
preDispatch(), postDispatch() or
action methods, providing an action, controller,
module, and optionally any additional parameters you may wish to
send to the new action:
<?php
public function fooAction()
{
// forward to another action in the current controller and module:
$this->_forward('bar', null, null, array('baz' => 'bogus'));
}
public function barAction()
{
// forward to an action in another controller:
// FooController::bazAction(),
// in the current module:
$this->_forward('baz', 'foo', null, array('baz' => 'bogus'));
}
public function bazAction()
{
// forward to an action in another controller in another module,
// Foo_BarController::bazAction():
$this->_forward('baz', 'bar', 'foo', array('baz' => 'bogus'));
}




