问题描述
我的loginAction
位于user
模块中,在控制器application/modules/user/controllers/AuthController.php
中.我想在成功登录后重定向到 application/controllers/IndexController.php
中的 indexAction
.所以我有这个:
My loginAction
is in a module user
, in the controller application/modules/user/controllers/AuthController.php
. I want to redirect upon successful login to the indexAction
in application/controllers/IndexController.php
. So I have this:
if ($result->isValid()) {
$auth->getStorage()->write($adapter->getResultRowObject());
$this->_helper->redirector('index', 'index');
return;
}
当我现在登录时,我收到消息 Message: Invalid controller specified (index)
.我想这是因为我的登录名在模块 user
中,而 IndexController
在根应用程序中.
When I now login, I get the message Message: Invalid controller specified (index)
. I guess it is because my login is in the module user
, while the IndexController
is in the root application.
我该如何解决这个问题?
How can I fix this?
推荐答案
redirector() 动作助手有几种方法来重定向请求.
The redirector() action helper has several methods to redirect the request.
试试这个,application/controllers 中的控制器位于 'default' 模块中:
try this, the controllers at application/controllers are in the 'default' module:
if ($result->isValid()) {
$auth->getStorage()->write($adapter->getResultRowObject());
//redirector($action, $controller, $module)
$this->_helper->redirector('index', 'index', 'default');
}
我更喜欢使用这个助手的方式更明确,所以我不必记住默认值:
The way I prefer to use this helper is more explicit, so I don't have to remember the defaults:
if ($result->isValid()) {
$auth->getStorage()->write($adapter->getResultRowObject());
//gotoSimple($action, $controller, $module, $params = array())
$this->getHelper(redirector)->gotoSimple('index', 'index', 'default');
//or use gotoUrl($url)
$this->getHelper(redirector)->gotoUrl('/index/index');
//or use gotoRoute()
$this->getHelper(redirector)->gotoRoute('action'=>'index', 'controller'=>'index', 'module' => 'default');
}
以及快速而肮脏的实用方法:
and the quick and dirty utility method:
if ($result->isValid()) {
$auth->getStorage()->write($adapter->getResultRowObject());
//_redirect($url);
$this->_redirect('/index/index');
}
希望能帮到你
这篇关于Zend1:重定向到不同模块中的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!