It is a bit more complicated and not always I need to redirect to the
referer. The controller checks if there is a "redirect_id" value setup
in the submited form and changes the default redirect with the one
from the form.
After submitting the form, if I pr the redirect_id i get for example:
array("action" => "browse", [0] => 54)
so ... so far it is working, also if manually i go to the /browse/54
url everything is fine and working
And the only way I was able to pass an array into the form was to
encode it. If there is some other better way, please advise.On Fri, Nov 18, 2011 at 2:54 PM, AD7six <[email protected]> wrote: > > > On Friday, 18 November 2011 13:24:16 UTC+1, Constantin.FF wrote: >> >> I am trying to get page redirected (after add or edit) depending on a >> field of the form. Here is what I have done so far: >> >> View: >> ... >> $back_link = array('action' => 'browse', $this->Form- >> >value('Post.parent_id')); >> echo $this->Form->hidden('redirect_id', array('value' => >> json_encode($back_link))); > > why do you need to json encode the referer(ish) url >> >> ... >> >> Controller: >> ... >> $redirect = (array)json_decode($this->data['redirect_id']); >> $this->redirect($redirect); >> ... >> >> When I pr() the $redirect , everything looks just as it should but i >> get redirected to the browse action without any id after it. > > are you sure about that. put it through Router::url and/or check that > /foo/123 isn't redirecting to /foo > >> >> How to make this working, is it necessary to use separated fields in >> the view for controller, action, id. Or if you can advise any other, >> more simple method to do this. > > pass the url as a string (why do array -> encode -> decode -> string, when > you could simply do array -> string) - or if you are trying merely to go > back where you were when the form was submitted - use $this->referer() > (either directly or by storing the current url in your "go back here" form > field > AD > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > [email protected] For more options, visit this group at > http://groups.google.com/group/cake-php > -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
