我正在创建一个简单的网站,用户可以在其中注册,然后登录并添加文本文章。如果没有登录,访问者将具有访客的角色,并且只能查看文章。我在 Zend Framework 1 中做这个练习,因为我刚刚开始学习 Zend。我将为登录创建一个 Controller AuthController,但我想知道如何从 IndexController 中的 indexAction 重定向到该 Controller 中的登录操作。另外,如何使用自定义插件来实现这种访问控制?如何调用它?
最佳答案
jalpesh 和 Hasina 的简短回答都是正确的。
Jalpesh 的示例将是对操作助手 redirector()
的简写调用,默认为重定向的 gotoSimple()
方法,除了他似乎有参数向后。
//corrected
$this->_helper->redirector($action, $controller);
更详细地称为:
$this->getHelper('Redirector')->gotoSimple($action, $controller = null, $module = null, array $params = array());
有几种方法可以使用 Redirector action helper ,这只是一个很常见的例子。
Hasina 提供的示例是对 Controller 的调用utility method _redirect()
比 Redirector
助手代码少得多,但仍然非常有用。
//only accepts a url string as the first arg
//deprecated as of ZF 1.7 still in documentation
$this->_redirect($url, array $options = array());
显然,从 ZF 1.7 开始,有一种新方法不在文档中(在文档 block 中找到了这一点),它是首选的:
//valid as of ZF 1.7, not in documentation
$this->redirect($url, array $options = array());
这两个实用方法都是代理:
Zend_Controller_Action_Helper_Redirector::gotoUrl()
希望对你有帮助
关于php - 如何在 Zend 中重定向到不同的 Controller 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16833243/