Welcome Guest, Not a member yet? Register   Sign In
How to include $this->data into redirect() ?
#1

[eluser]whygod[/eluser]
Hi usually I use these codes below,
Code:
$this->load->view('template/master', $this->data);

But how do I include $this->data into redirect method() ?
Code:
redirect('front/home_page');

Thanks in advanced.
#2

[eluser]whygod[/eluser]
Also is redirect() a php built-in method or CodeIgniter built-in method?

Thanks in advanced.
#3

[eluser]Aken[/eluser]
Why? redirect() is a CodeIgniter function that sets a Location header, sending the user to a new URL and completely new request. You don't need to pass data to redirect().
#4

[eluser]Ed Robindon[/eluser]
I suppose if you need to pass data you could put it in a session's data then redirect.
#5

[eluser]ramirors[/eluser]
redirect is header location so user session, load->view is as include thats why you can send data.
#6

[eluser]boltsabre[/eluser]
As mentioned above:

- redirect() is CI based, not a native PHP function.
- it sends the user to a completely new URL by setting a php based Location header.
- because http is a stateless environment, this means that any variables, class instantiations, etc, are lost after performing a http redirect. You are effectively starting afresh.

- So... to pass data from on controller, to another controller, you need to store it somewhere before you do the redirect(), and then retrieve it after the redirect.
- The 4 most common methods, in CI, in my preferred order, for this scenario, are: flashdata, sessiondata, cookie, database.

Flashdata is best, because you set it before the redirect, retrieve it after the redirect, and then it's gone, you don't have to worry about unsetting/deleting it or anything, it's own "garbage disposal" handles all this for you.




Theme © iAndrew 2016 - Forum software by © MyBB