-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何终止程序运行而又不影响几个hook的执行 #121
Comments
throw exception.. |
尝试过exception,并且将exception交给errorController处理,但是同样postDispatch和dispatchLoopShutdown两个hook不执行 |
hmm, 我看看, 如果真的是这样, 那应该是bug了... |
个人感觉应该提供一个forceFinishDispatch这样的方法,throw exception略感山寨 |
exception交给errorController处理,但是同样postDispatch和dispatchLoopShutdown两个hook不执行 同现 |
如我们在群里的讨论, 你可以通过这个方式来实现: public function init() {
$this->DontExecute = true;
}
public function action() {
if ($this->DontExecute) { return; }
} 另外我们也可以考虑对init加入支持, 比如如果init返回false就不在继续执行action. 但是问题在于, 如果init返回false, 框架应该怎么做, 抛出异常? 还是静默处理? 总感觉不对劲. thanks |
如果在每个action里都去判断这个属性是否为true很不方便,也容易遗漏。 |
init加入return false 不执行action 不行。不一定是init比如说 不要通过xxAction的返回去判断当前controller的停止 Yaf_Dispatcher对应的地方是(伪代码,没细看yafc代码,话说看也看不懂) 以前可能是这样的: $action=将要执行的方法 修改成这样的: $c = new controller(); |
已经解决 参考这里
https://github.com/letwang/HookPHP/blob/master/app/admin/plugins/Hook.php |
ErrorController确实并不会执行postDispatch和dispatchLoopShutdown,这个问题会解决么 |
emmm 15年讨论到19年 我是20年了,同问,有没有优雅的方式,比如init return false就不执行action了 |
21年了,我也来问一遍 |
这个问题解决了 我也需要用这个方法 |
有两个场景
以上两个场景可以在代码后面跟上exit或者die来实现,但这样的话会导致postDispatch和dispatchLoopShutdown两个hook不执行
The text was updated successfully, but these errors were encountered: