phalcon--Scheduling Controller

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.