【发布时间】:2010-09-23 01:55:45
【问题描述】:
我们正在尝试向 AccountController 添加几个操作,以便在忘记密码发布操作之后添加另一个操作。问题是如果我们将操作添加到 preDispatch 逻辑以确保您不必登录它仍然会重定向回登录页面。
public function preDispatch()
{
// a brute-force protection here would be nice
parent::preDispatch();
if (!$this->getRequest()->isDispatched()) {
return;
}
$action = $this->getRequest()->getActionName();
if (!preg_match('/^(create|login|logoutSuccess|forgotpassword|forgotpasswordpost|confirm|confirmation|newactionhere)/i', $action)) {
if (!$this->_getSession()->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
} else {
$this->_getSession()->setNoReferer(true);
}
}
这不起作用,因为我们首先调用父级,它也运行它,但当然 preg_match 不匹配,它运行运行方法 $action->getResponse()->setRedirect( $url) 当然设置标题,当它返回到我们的代码时,它并不重要,然后重定向。
我们可以只删除对父级的调用,但我不确定这是最好的方法,因为父级也会调用其父级,它会运行一些东西来设置布局区域,然后还会调用父级方法。我想只用 Mage_Core_Controller_Front_Action 调用父级,但也不确定这是否是正确的方法。
【问题讨论】:
标签: redirect magento controller