【问题标题】:Zend Framework: Redirect from action helperZend 框架:从动作助手重定向
【发布时间】:2012-09-13 12:24:03
【问题描述】:

那是我的控制器助手:

class Application_Controller_Helper_Test extends Zend_Controller_Action_Helper_Abstract
{
    public function preDispatch()
    {
        $this->_helper->redirector->gotoUrl('/index/index');
        // ...
    }

但有错误,我无法修复:

在非对象上调用成员函数gotoUrl()

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    如果您想从动作助手重定向,您必须从助手代理检索重定向助手。下面的 sn-p 会重定向到index/index

    $controller = $request->getControllerName();
    $action = $request->getActionName();
    
    // Prevent redirection loop
    if ($controller.'/'.$action !== 'index/index') {
        $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
        $redirector->gotoSimpleAndExit('index', 'index', 'default');
    }
    

    【讨论】:

    • 我不知道为什么但无法打开索引/索引:Firefox 提示:页面未正确重定向
    • 我认为你有一个重定向循环。检查我的答案。
    【解决方案2】:
    $this->_redirector = $this->_helper->getHelper('Redirector');
    

    $this->redirector('targetAction', 'targetController');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多