cook
  • Home
     
  • About Me
     

Redirecting to the proper page after actions

Jimmy Bourassa | November 29, 2008

A couple days ago, a client I currently work for found a little annoyance with cakePHP default’s behaviour of redirecting to the index action after a delete or edit action, thus ignoring the page you were on.

Indeed, redirecting to $this->referer wouldn’t work in this case because the data is posted to the same action, therefore $this->referer = $this->here. The solution is quite simple, add this code to your action:

if ($this->referer != $this->here)
	$this->Session->write('referer', $this->referer);

Then, if your save method is successful, you can safely redirect with the Session variable that’s just been set :

$this->redirect($this->Session->read('referer'));

It’s pretty simple, but I guess it might come in handy. Thanks to TommyO from the irc channel for this hint!

Comments rss
Comments rss

Sort search results by relevance »

2 responses

look at this solution, also very nice if you can

cakemate | March 5, 2009

look at this solution, also very nice if you can not rely on referer:
http://www.pseudocoder.com/archives/2008/01/24/cakephp-pagination-recall-component/

Every one understands that today's life is not very cheap,

ERMA26Mcdonald | November 9, 2011

Every one understands that today’s life is not very cheap, however people require money for various issues and not every person gets big sums money. Hence to receive quick business loans and collateral loan will be good way out.

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

Recent Posts

  • OpenX and HostGator shared hosting
  • Common mistakes when working with accentuated characters
  • Model “X” with multiple associations leading to Model “Y”
  • Sort search results by relevance
  • Redirecting to the proper page after actions

People I like

  • Jean-Philippe Doyle
  • Knowland Design
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox