简体   繁体   English

无法使用ZF1.12重定向器助手在try / catch中重定向

[英]Cannot redirect in try/catch with ZF1.12 Redirector helper

I'm facing a weird problem. 我面临一个奇怪的问题。 It appears I cannot use ZF1.12 Redirector Helper in the catch() {} expression. 看来我不能在catch() {}表达式中使用ZF1.12 Redirector Helper。 Here is my code: 这是我的代码:

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

It appears that using route names in the helper (commented out line) doesn't work in the catch() {} expression. 看来在helper(带注释的行)中使用路由名称在catch() {}表达式中不起作用。 Code is interpreted as the flash message appears when I go manually to another page (and the echo $e->getMessage() is displayed on the error page) but it simply doesn't redirect where it should as I'm left with a blank page. 当我手动转到另一个页面时,代码被解释为出现闪动消息(并且在错误页面上显示echo $e->getMessage() ),但是它根本没有重定向到应该出现的位置,因为我只剩下一个空白页。 The next line after the commented one is, of course, working. 评论后的下一行当然是有效的。

I want to use route names as I may change URL afterwards. 我想使用路由名称,因为以后可能会更改URL。

Many thanks. 非常感谢。

As you noticed gotoRoute is something you are looking for: 如您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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM