CodeIgniter Forums
Redirecting to another controller passing the variable $data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Redirecting to another controller passing the variable $data (/showthread.php?tid=10901)



Redirecting to another controller passing the variable $data - El Forum - 08-17-2008

[eluser]jeffersonrpn[/eluser]
I have a controller taht load records from a table and redirect to a view to show this records in a table. In this table I have, for each row, a "delete" link to remove the record.
I want to call a controller ("record/delete/1", for exemple), create a success message ($data['message']) and call back the first controller to show again the record.

A good way to do this is the way that this forum redirect you in a search or in login.

ThanksĀ“.


Redirecting to another controller passing the variable $data - El Forum - 08-17-2008

[eluser]Colin Williams[/eluser]
Use Session flashdata to set and retrieve the message in the respective controller methods.


Redirecting to another controller passing the variable $data - El Forum - 08-18-2008

[eluser]eilrahc[/eluser]
I ran across this a couple weeks ago. Here's how I did it.

In the table, I show a delete link that looks like 'record/delete_confirm/$id'.

'delete_confirm' just presents a form to the user with Yes and No buttons. The form action is set to another controller method called 'delete', which looks like this:

Code:
public function delete() {
    if ($_POST['delete_confirm'] == "Yes") {
        $this->table_model->delete($this->uri->segment(3));
    }
    redirect('table');
}

The 'delete' method in the model does the work of actually removing the row. I should probably have some error checking in here (to check for a valid $this->id), but this is the gist of it anyway. The benefit to doing it this way is that you don't need an intermediate "hey, I'm doing what you asked" page, especially for something so small as deleting a row from the database.


Redirecting to another controller passing the variable $data - El Forum - 06-11-2010

[eluser]Unknown[/eluser]
[quote author="Colin Williams" date="1219055961"]Use Session flashdata to set and retrieve the message in the respective controller methods.[/quote]

Thank you, just what I was looking for.