Welcome Guest, Not a member yet? Register   Sign In
redirect
#1

[eluser]Harshala[/eluser]
Code:
How to pass parameter say $data while using redirect() from one function of controller to another
#2

[eluser]pickupman[/eluser]
You will like need to use the session to pass the data. If you only need the data for the next page request you would use:
Code:
$this->session->set_flashdata($data);

Or if you would like the parameter to persist through the entire session use:
Code:
$this->session->set_userdata($data);

Check out the [url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]Session[/url] library.
#3

[eluser]Harshala[/eluser]
Code:
Thanks for the reply. Actually I want to redirect to the same function from different functions with different data, so I cant store it in session all the time, is there any other method to pass the control to that function along with parameter
#4

[eluser]Harshala[/eluser]
Code:
I am searching this only to optimize the code otherwise there is redundancy in the code. So kindly let me know if you have any solution.
#5

[eluser]pickupman[/eluser]
I have used something when doing a login redirect, is save the url in the users session, and then upon logging in redirect back to the page they last clicked. You can use the same idea, save to the users session the string you want to redirect to, and also what data. Then in your controller that will handle the redirect, use both pieces of information in the Controller to handle it.

Again, without a specific explanation or example, or question is somewhat vague. Here is an example of what I am trying to explain:
Code:
$this->session->set_userdata('redirect_uri', 'after_redirect_controller'); //What page to go to after redirect controller
$this->session->set_userdata($data);
redirect('redirect_controller');

//Redirect Controller
function index()
{
  $redirect_uri = $this->session->userdata('redirect_uri');
  
  //Do something with other variables from session here

   redirect($redirect_uri);
}
#6

[eluser]Harshala[/eluser]
Code:
Thanks a lot! You made my day.




Theme © iAndrew 2016 - Forum software by © MyBB