2014-07-22 43 views
0

我面臨一個奇怪的問題。看來我不能在catch() {}表達式中使用ZF1.12 Redirector Helper。這裏是我的代碼:不能重定向在try/catch與ZF1.12重定向幫手

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(); 
    } 

看來,在幫助中使用路由名稱(註釋線)不會在catch() {}表達工作。代碼被解釋爲當我手動進入另一個頁面(並且在錯誤頁面上顯示echo $e->getMessage())時出現的閃爍消息,但是它只是沒有重定向到應該留下的空白頁面。當然,評論之後的下一行當然是有效的。

我想使用路由名稱,因爲之後我可能會更改URL。

非常感謝。

+1

很顯然,我需要使用'gotoRoute()'方法,而不是'setGotoRoute()'。 – D4V1D

回答

0

正如你注意到​​是你正在尋找的東西:

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'); 
}