Kim*_*nce 6 php zend-framework
我正在对Action Helper的preDispatch方法进行ACL检查.当它失败时,我想调用动作控制器的_redirect方法,但是我很难做到这一点.
在这篇文章附带的评论中,zend-framework从另一个动作助手中调用动作助手,我看到两个解决方案.在第一个中,控制器从助手访问为$ this - > _ actionController.在第二个中,使用$ this-> getActionController()访问它.
我尝试了以下两种方法:
$this->_actionController->_redirect('/');
$this->getActionController()->_redirect('/');
Run Code Online (Sandbox Code Playgroud)
在任何一种情况下,我得到'方法'_redirect'不存在......'.是否可以限制从动作帮助程序访问哪些控制器方法?
Mar*_*cin 14
有重定向动作助手,你可以在你的动作助手使用.例如:
class My_Controller_Action_Helper_Test extends Zend_Controller_Action_Helper_Abstract {
public function preDispatch() {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
$redirector->gotoUrl('/url');
}
}
Run Code Online (Sandbox Code Playgroud)
Controller的_redirect方法只是重定向器方法的包装器gotoUrl.