Welcome Guest, Not a member yet? Register   Sign In
Re-routing execution to a different controller
#1

[eluser]philmctim[/eluser]
Say I have the following:

1) An page that lists all the rows in a table. It has an 'insert' button that takes you to...

2) A form page that lets you enter a new value in the table.

I would like the 'success' page of (2) to take the user back to (1). So once the validation is complete and the row is inserted, I want to re-direct the control flow to a different controller function (the two controller functions may be in different controller files).

Any tips?

Thanks.
#2

[eluser]Gavin Blair[/eluser]
Quote:Say I have the following:

1) An page that lists all the rows in a table. It has an ‘insert’ button that takes you to…

2) A form page that lets you enter a new value in the table.

I would like the ‘success’ page of (2) to take the user back to (1). So once the validation is complete and the row is inserted, I want to re-direct the control flow to a different controller function (the two controller functions may be in different controller files).

Any tips?

Thanks.

If I understand your problem correctly, I think you want (2) to pass a message to (1).

I would put something like the following in the view of (1):

Code:
&lt;?=isset($message) ? '<div id="alert">' . $message . '</div>' : ''?&gt;

And then I would have the controller function of (1) look like this:

Code:
function displaystuff($message = '') {
  //get ready to display the rows of the table
  ...

  $data['message'] = $message;
  ...
  $this->load->view(..., $data);
}

And the function of the form like this:

Code:
function process_data() {
  //process the POST input
  ...

  //send the success message
  $this->displaystuff('The form was successfully processed');
}

I know this works when both functions are in the same controller. I am not sure it will work when they are separate controllers.

Hope this helps
Gav
#3

[eluser]Colin Williams[/eluser]
It's usually best to handle messages with session flashdata, this way you can simply redirect them, via the redirect() function, and still rely on message info to be available after a new HTTP request
#4

[eluser]philmctim[/eluser]
Thanks, I'll give it a try.




Theme © iAndrew 2016 - Forum software by © MyBB