如何在 Kohana 中停止执行请求?
假设我有一个带有像这样的 before 函数的控制器模板...
public function before()
{
parent::before();
if ($this->request === Request::instance())
{
// its a main request, throw an exception or redirect
Request::instance()->redirect('/');
}
else
{
// ok
}
}
但是假设我不想重定向,我想停止请求流,并且什么也不做。
异常会这样做吗?有没有一种简单的方法,例如 Request::die();
?
编辑:: 我实际上不想停止请求流,只是阻止该控制器执行任何操作。该控制器很可能是从另一个控制器调用的,我想将控制权传递回调用控制器。
谢谢!
Let's say I have a controller template with a before function like so...
public function before()
{
parent::before();
if ($this->request === Request::instance())
{
// its a main request, throw an exception or redirect
Request::instance()->redirect('/');
}
else
{
// ok
}
}
But let's say I don't want to redirect, I want to stop the Request flow, and do nothing.
Does an exception do this? Is there a simple way, like Request::die();
?
EDIT:: I actually don't want to halt the Request flow, just prevent this controller from doing anything. It's likely that this controller was called from another controller, and I want to pass the control back to the calling controller.'
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1.使用异常(尚未测试):
更改操作名称:
$this->请求->action('遗忘'); // 重定向到不执行任何操作的“oblivion”操作
1.Use exceptions (not tested yet):
Change action name:
$this->request->action('oblivion'); // redirects to an "oblivion" action that does nothing
您可以在
before()
中设置一个类变量:然后在您的操作中:
You can set a class variable in
before()
say:Then in your action: