Ari Takeshi
Ari Takeshi

Reputation: 934

CakePhp Refreshing page

I have the following problem in Cakephp: I maded a CMS to edit the content of a website with CakePhp. Now when I change the content in my form and I click Save then he shows again the data from before the form was changed. In the database everything saved well and if I refresh the page also he shows the right data.

I know I can render a new page or redirect to another page, but I liked to just show a message with setFlash and that's it. Someone can help me out?

Thanks in advance

Aäron

Upvotes: 3

Views: 18890

Answers (2)

Mouloud
Mouloud

Reputation: 3795

Update : check the Justin T. solution below.

You can just redirect to the same page:

to set your flash message:

$this->setFlash('blablablabla');

and

return $this->redirect($this->here); //cake 1.3

or

return $this->redirect($this->request->here); // cake 2.x

or

return $this->redirect(['controller' => 'MyController', 'action' => 'methodOfController']); // cake3.X

to redirect.

Upvotes: 16

Justin T.
Justin T.

Reputation: 3701

With the new method flash() you set a message and redirect in the same method.

This is the most elegant way I know of, and it goes something like this :

<?php
public function post() {
   // process content here...


   // redirects the user immediately with a nice message
   $this->flash('Your post has been updated, thanks', 'index');

}

Hope this helps !

Upvotes: 2

Related Questions