Zend请求对象重定向

时间:2011-01-24 07:56:10

标签: zend-framework response httpresponse

我遇到了一个问题,即在验证失败时使用响应对象转到其他控制器。

设置是一个控制器(userPages),它调用动作助手(公共)然后尝试验证用户,如果失败则应该将用户发送到系统内的另一个URL。代码的相关部分是:

            /*
             * user was never logged in force them to login now
             * we dont have access to any other helper methods so set it the long hard way...make
             *  sure to specify setDispatched to false to reque the dispatch event
             */
            return $this->getRequest()->setModuleName('default')
                                      ->setControllerName('index')
                                      ->setActionName('login')
                                      ->setDispatched(false);

我最初在zend 1.6和php 5.2.3中使用了这个片段(并且它工作得很好),我提到这个因为我怀疑从那以后事情可能会变得稍微复杂一些,但我似乎无法在文档中找到任何内容这表明需要不同类型的重定向或失败的原因。有人有主意吗? btw:default / index / login是我服务器上的有效路径,我确信它到达上面的行,并在返回和静默失败之前成功设置所有参数。

2 个答案:

答案 0 :(得分:0)

如果您想从一个动作重定向到另一个动作,您可以使用:

$this->_redirect('/index/login');

您也可以尝试redirector action helper。希望这是你想要实现的目标。

答案 1 :(得分:0)

显然,当我最初从动作助手中尝试重定向器时,我有一个拼写错误,从Zend_Controller_Action_Helper_Abstract继承的动作助手的正确语法是:

//in case we need to redirect preload the redirector
$redirector =  $this->_actionController->getHelper('Redirector');
$redirector->gotoUrl('<your url here>');
相关问题