【发布时间】:2014-04-23 13:54:13
【问题描述】:
我正在尝试从动作重定向到同一控制器中的另一个动作,代码如下:
class IndexController extends AbstractActionController
{
public function doAction()
{
var_dump('doAction');die;
}
public function indexAction()
{
return $this->redirect()->toRoute('application',array('controller'=>'index','action' => 'do'));
}
}
但在 chrome 浏览器中显示“此网页有重定向循环” 我试图完全重定向到其他控制器:
return $this->redirect()->toRoute('application',array('controller'=>'auth','action' => 'login'));
但结果相同。 注意: 我已将 module.config.php 中的路由从 /application 更改为 /v1 这是我做出改变的部分:
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/v1',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][_a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
是这个原因吗? (尝试将 v1 替换为默认应用程序,但结果没有变化)
为什么我不能重定向到行动? 任何想法将不胜感激。
【问题讨论】:
-
这对我有用
return $this->forward()->dispatch("Application\Controller\Index", array("action" => "do"));但仍然不知道为什么重定向不起作用.. -
你需要弄清楚循环是什么——浏览器重定向到什么 URL?检查标题(例如 Chrome 中的网络标签)以查看
标签: php redirect zend-framework2