How to include $this->data into redirect() ? - 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: How to include $this->data into redirect() ? (/showthread.php?tid=56260) |
How to include $this->data into redirect() ? - El Forum - 12-05-2012 [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. How to include $this->data into redirect() ? - El Forum - 12-05-2012 [eluser]whygod[/eluser] Also is redirect() a php built-in method or CodeIgniter built-in method? Thanks in advanced. How to include $this->data into redirect() ? - El Forum - 12-05-2012 [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(). How to include $this->data into redirect() ? - El Forum - 12-06-2012 [eluser]Ed Robindon[/eluser] I suppose if you need to pass data you could put it in a session's data then redirect. How to include $this->data into redirect() ? - El Forum - 12-11-2012 [eluser]ramirors[/eluser] redirect is header location so user session, load->view is as include thats why you can send data. How to include $this->data into redirect() ? - El Forum - 12-12-2012 [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. |