tags:

views:

28

answers:

1

Hi all,

I am using cakePHP and is making a very simple message board.
I came across a question, and I have no idea how to solve it:

Let say there were ten records in the Table Reply,
and a user has just successfully made a new reply to the Table. So there are eleven records now.
After the new record is made, I use this to redirect the user back to the index:

$this->redirect(array('action' => 'index'));

But I am thinking to make the message board more user-friendly by trying to redirect the user back to the reply which he has just added successfully.

Do you have any ideas?

+2  A: 

Sure, Cake allows you to do this within your redirect code.

$this->redirect(array('action' => 'reply', $id));

Should probably do it. Note that $id is already populated by Cake, so all you need is the correct view title.

hollsk
Just to be clear here, **reply** should be the action used to view your post. When adding additional variables in the array (like $id in the example above) these variables get appended in the URL. So the above redirect will end up like **http://<cake-base-url>/<controller the redirect came from>/reply/<$id value here>**
Michael
@placer14, thank you for the help.
@placer14, thanks. What should I add to the array in the Redirect function if pagination is used, say the user was in page 2 before he added a new reply.
You would add the page number to the redirect array. See duplicate here: http://stackoverflow.com/questions/1055359/maintaining-page-number-after-redirect-in-cakephp
hollsk