To bind a listener to a component:
Use Phalcon\mvc\dispatcher as Mvcdispatcher,
Phalcon\events\manager as Eventsmanager;
$di->set (' Dispatcher ', function () {
Create an event management
$eventsManager = new Eventsmanager ();
attach a listener to the "dispatch" type
$eventsManager->attach ("Dispatch", Function ($event, $dispatcher) {
// ...
});
$dispatcher = new Mvcdispatcher ();
to bind a $eventsManager to a view component
$dispatcher->seteventsmanager ($eventsManager);
return $dispatcher;
}, True);
An instantiated controller is automatically used as the listener for event scheduling, so you can implement a callback function:
Class Postscontroller extends \phalcon\mvc\controller
{
Public Function Beforeexecuteroute ($dispatcher)
{
execute before every action found
}
Public Function Afterexecuteroute ($dispatcher)
{
execute after each found action
}
}
Forward execution flow to another controller / action:
$this->dispatcher->forward (Array (
"Controller" = "POST",
"Action" = "index"
));
$this->dispatcher->forward (Array (
"Action" = "search",
"params" = = Array (1, 2, 3)
));
(By default, the passed parameters are passed to the corresponding action in the order of the URL , and you can simply tweak your app to match the URL format you want. )
Get Parameters:
Get all parameters:
$params = $this->dispatcher->getparams (); gets an array of
Gets the specified parameter:
$content = $this->dispatcher->getparam (' content '); gets the value of a parameter
With the right scheduling loop event, you can also do:
URL Adjustment Conversion action name
Remove legacy extensions to inject model instances
Handling not-found Errors
Attention:
Making a "forward" is not the same as making an HTTP redirect . Although the two appear to have the same final effect. "forward" does not reload the current page, all redirects occur in only one request, and HTTP redirection requires two requests to complete the process.
phalcon--Scheduling Controller