On Mar 9, 11:26 am, Danny Lieberman <[email protected]> wrote:
> This would seem to be a trivial task. I have a list of paginated
> rows. I want to be able to click on an edit operation on a
> particular page > 1 and return to the same page. I save the referer
> on entry to the function and redirect to the saved referer after the
> database save operation - but the controller always returns to the
> controller index method no matter what the user chooses.
>
> I'm running in production mode - perhaps this is related to debug=0?
>
> Here is the code:
> function fu($id = null) {
> $refer = Controller::referer(); // save the calling
> page
> if (!$id && empty($this->data)) {
> $this->Session->setFlash(__('Invalid Contact',
> true));
> $this->redirect(array('action'=>'index'));
> }
> echo$refer;
> if (!empty($this->data)) {
> if ($this->Contact->save($this->data)) {
> $this->Session->setFlash(__('The
> Contact has been saved', true));
> // $this->redirect(array
> ('action'=>'index'));
> $this->redirect($refer); // redirect
> back to the calling page after save
> } else {
> $this->Session->setFlash(__('The
> Contact could not be saved. Please, try again.', true));
> }
> }
> if (empty($this->data)) {
> $this->data = $this->Contact->read(null, $id);
> }
> $this->set('contact', $this->Contact->read(null,
> $id));
>
> Looks like something really stupid is breaking this but I cant figure
> out what
>
> Danny
Try this logic:
In the controller:
if (!$this->data) {
$this->set('referer', $this->referer($default));
} else {
if ($this->Model->save()) {
$this->redirect ($this->data['_App']['referer']);
}
}
in the view:
...
echo $form->input('_App.referer', array('value' => $referer, 'type' =>
'hidden'));
...
Personally, I always add a referer to all forms to use for exactly the
purpose you highlight.
hth,
AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---