Home > Article > Backend Development > How Phalcon uses events to manage controllers
Define a public $a=true
;
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?
Define a public $a=true
;
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
.