Your Location is: Home > Cakephp
Saving request data in CakePHP between two actions in controller
Question
I have two actions which are like pages in my controller. I two buttons: next
and previous
too. How can I save my $this->request->data
between two action in the same controller ? When i'm pressing previous
, i need to have all the data on the previous page, which the user entered not to disappear.
Best answer
If you dont have lots of fields and fields are named uniquely, you could add correspondig values to session when handling form in controller.
$this->Session->write('Form1.field1', $value);
After that, you could fetch saved values from session every time you visit that form page again and use them as default values in form.
$this->set('Form1.field1', $this->Session->read('Form1.field1'));
I must admit, that this is not very handy way doing it, and by my self, I would definetly go with JavaScript instead.