[英]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.