Controllers respond to requests via actions, and in some cases these actions require parameters to tell the controller to perform a specific task that might relate to a model, view, or other action. Automatic routing controllers simply define every action within the controller as a route. For more information on how the routing mapping mechanism works continue on to the defining routes section.
To create an automatic routing controller, simply add $this->addRoute($this->action); to the initalize function of the controller. The code automatically registers the current action since $this->action is a reference to the action's name.
Below the ErrorController has been shortened for the purposes of this example.
<?php
class ErrorController extends FrontController
{
/**
* Initialization
*
*/
public function initialize()
{
$this->addRoute($this->action);
}
} /*end of class ErrorController*/The initialize() method is a special function that is ran before any controller action is processed. It is the recommended convention for doing any special initialization that is needed by the controller. It can also be used to setup any dependencies needed by the controller's actions.