Home > Backend Development > PHP Tutorial > How Phalcon uses events to manage controllers

How Phalcon uses events to manage controllers

WBOY
Release: 2016-08-04 09:22:08
Original
1129 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template