Cphalcon: Dispatcher forward forwarding to controller but the URL is not changing.

Created on 12 Dec 2012  路  4Comments  路  Source: phalcon/cphalcon

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

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:

$this->response->redirect("user/login");

All 4 comments

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!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yakovlev-Melarn picture Yakovlev-Melarn  路  3Comments

hesalx picture hesalx  路  4Comments

mynameisbogdan picture mynameisbogdan  路  3Comments

abcpremium picture abcpremium  路  3Comments

fonqing picture fonqing  路  3Comments