![]() |
using redirect() help? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: using redirect() help? (/showthread.php?tid=27445) |
using redirect() help? - El Forum - 02-11-2010 [eluser]chefnelone[/eluser] Hello I'm trying to use redirect() but I can't do it. I'd like to call this method (set_language) from any view-page and then just refresh that view-page. If I use this code it takes me to my base_url adding '1' as a segment. In controller called 'site;' I have: Code: function set_language(){ What's is missing? using redirect() help? - El Forum - 02-11-2010 [eluser]rogierb[/eluser] You redirect to page 1 since it redirects to whatever the first parameter is. If you want to refresh the current page, try something like Code: redirect(uri_string()); using redirect() help? - El Forum - 02-11-2010 [eluser]hccoder[/eluser] Hello, If you wanna refresh current page try this: function set_language(){ redirect(uri_string(), 'refresh'); } edit: im too slow ![]() using redirect() help? - El Forum - 02-11-2010 [eluser]chefnelone[/eluser] I tried. but didn't work for me. I load 'myViewPage' from a controller called 'catalog' ...185.33.1.1/catalog/myViewPage with a link: Code: <a href="site/set_language/english">Run set_language and refresh this page</a> Then I have the 'site' controller with: Code: function set_language(){ When I hit the link the browser takes me to this url: ...185.33.1.1/index/set_language/english instead of ...185.33.1.1/catalog/set_language/english Maybe the cause is that I have the function 'set_language' in the 'site' controller but I load the 'myViewPage' from 'catalog' controller. Should I have all in one controller to get redirect() working properly? using redirect() help? - El Forum - 02-11-2010 [eluser]hccoder[/eluser] It won't work in this way, because when you click on the link, the the app lives the 'catalog' controller, and you will refresh the 'site' controller. Try to save the current page in session_flashdata in the 'catalog': function site() { parent::Controller(); $this->session->set_flashdata('last_url', uri_string()); } and try this in the site/set_language: function set_language(){ redirect($this->session->flashdata('last_url') ![]() } using redirect() help? - El Forum - 02-11-2010 [eluser]chefnelone[/eluser] [quote author="hccoder" date="1265902757"]It won't work in this way, because when you click on the link, the the app lives the 'catalog' controller, and you will refresh the 'site' controller. Try to save the current page in session_flashdata in the 'catalog': function site() { parent::Controller(); $this->session->set_flashdata('last_url', uri_string()); } and try this in the site/set_language: function set_language(){ redirect($this->session->flashdata('last_url') ![]() }[/quote] It didn't works. :-S I understand from what you've said that if I just use 1 controller, it'll works fine. right? using redirect() help? - El Forum - 02-11-2010 [eluser]hccoder[/eluser] I don't know ![]() ![]() |