Reputation: 1186
I'm trying to redirect from Action to another action in same controller, here is the code:
class IndexController extends AbstractActionController
{
public function doAction()
{
var_dump('doAction');die;
}
public function indexAction()
{
return $this->redirect()->toRoute('application',array('controller'=>'index','action' => 'do'));
}
}
but in chrome browser says "This web page has redirect loop" I tried to redirect to completely other controller:
return $this->redirect()->toRoute('application',array('controller'=>'auth','action' => 'login'));
but the same result. NOTE: I was changed the route in module.config.php from /application to /v1 and this is part I made a change in:
'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(
),
),
),
),
),
),
is it the reason? (tried to replace v1 with application like default, but no change in result )
why can't I make redirect to action? any idea will be appreciated.
Upvotes: 0
Views: 480
Reputation: 471
Your code should be
return $this->redirect()->toRoute('application/default',array('controller'=>'index','action' => 'do'));
As your code isn't using the child route which allows you to override the controller / action
Upvotes: 2