I have a form which post to example.com/user/loginpost
In loginpostAction I have dispatcher forward like this
return $this->dispatcher->forward(
array(
'controller' => 'user',
'action' => 'login'
)
);
This load the user/login action but the URL in the browser remains example.com/user/loginpost
Hi Masood, yes dispatcher->forward perform an internal forward, this avoids to make an extra HTTP request, if you want that the URL change you must use a redirect:
$this->response->redirect("user/login");
Hi,
When I use
$this->response->redirect("user/login");
Any flashSession messages I had set using:
$this->flashSession->error("Username/password incorrect");
do not display.
Should i use both $dispatcher->forward and response->redirect. I am currently replacing
return $this->dispatcher->forward(
array(
'controller' => 'user',
'action' => 'login'
)
);
with
$this->response->redirect("user/login");
return;
After the page is reloaded with:
$this->response->redirect("user/login");
You can print the flash messages in your view using:
<?php $this->flashSession->output() ?>
The redirect doesn't stop the automatic rendering so it's recommended make the redirection like this:
$this->response->redirect("user/login");
$this->view->disable();
Thanks that worked!!
Most helpful comment
Hi Masood, yes dispatcher->forward perform an internal forward, this avoids to make an extra HTTP request, if you want that the URL change you must use a redirect: