扫码关注官方订阅号
在控制器中定义一个 public $a=true;
public $a=true
假如现在访问的是 index/index
index/index
我想用事件来对 $a 判断 如果为true 就正常访问 index/index,如果为false 就转发请求到 index/index2
$a
true
false
index/index2
请问可以做到不,
光阴似箭催人老,日月如移越少年。
最终执行:
Di::getDefault()->get('dispatcher')->forward([ 'contraller' => 'index', 'action' => 'index2' ]);
事件的话,可以考虑dispatcher的 beforeExecuteRoute.
dispatcher
beforeExecuteRoute
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
最终执行:
事件的话,可以考虑
dispatcher的beforeExecuteRoute.