[英]Cannot redirect in try/catch with ZF1.12 Redirector helper
我面临一个奇怪的问题。 看来我不能在catch() {}
表达式中使用ZF1.12 Redirector
Helper。 这是我的代码:
try {
$scp = new My_Controller_Plugin_Scp();
$scp->auth();
} catch(Exception $e) {
echo $e->getMessage();
// $this->getHelper('Redirector')->setGotoRoute(array(), 'routeName');
$this->_helper->redirector->gotoUrl('/url/');
exit();
}
看来在helper(带注释的行)中使用路由名称在catch() {}
表达式中不起作用。 当我手动转到另一个页面时,代码被解释为出现闪动消息(并且在错误页面上显示echo $e->getMessage()
),但是它根本没有重定向到应该出现的位置,因为我只剩下一个空白页。 评论后的下一行当然是有效的。
我想使用路由名称,因为以后可能会更改URL。
非常感谢。
如您gotoRoute
,您正在寻找gotoRoute
:
try {
throw new Exception('test');
} catch(Exception $e) {
//displaying message before redirect is not a good idea.
//Use flash messages
echo $e->getMessage();
$this->_helper->redirector->gotoRouteAndExit(array(), 'home');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.