Welcome Guest, Not a member yet? Register   Sign In
Redirecting to another controller passing the variable $data
#1

[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Ā“.
#2

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

[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.
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB