Home  >  Article  >  Backend Development  >  How Phalcon uses events to manage controllers

How Phalcon uses events to manage controllers

WBOY
WBOYOriginal
2016-08-04 09:22:081085browse

Define a public $a=true;

in the controller

If you are visiting index/index

I want to use events to judge $a. If it is true, access index/index normally. If it is false, forward the request to index/index2

Can you please do it?

Reply content:

Define a public $a=true;

in the controller

If you are visiting index/index

I want to use events to judge $a. If it is true, access index/index normally. If it is false, forward the request to index/index2

Can you please do it?

Final execution:

<code>Di::getDefault()->get('dispatcher')->forward([
    'contraller' => 'index',
    'action' => 'index2'
]);</code>

In case of events, you can consider dispatcher’s beforeExecuteRoute.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn