[英]How to stop execution of a Request in 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流,什么也不做。
这有例外吗? 有没有简单的方法,例如Request::die();
?
编辑::我实际上不想停止请求流,只是阻止此控制器执行任何操作。 该控制器很可能是从另一个控制器调用的,我想将该控件传递回调用控制器。
谢谢!
1.使用异常(尚未测试):
try
(
Request->instance()->execute();
}
catch (MyRequest_Exception $e)
{
// do what you want
}
echo Request->instance()->send_headers->response();
// somewhere in before()
if ($error)
{
throw new MyRequest_Exception($errortext);
}
更改动作名称:
$这 - >请求 - >操作( '遗忘'); //重定向到不执行任何操作的“遗忘”操作
您可以在before()
设置类变量,例如:
$this->execute = false;
然后在您的操作中:
public function action_example()
{
if (!$this->execute) return;
// etc
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.