Welcome Guest, Not a member yet? Register   Sign In
using redirect() help?
#1

[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(){
//do something;
redirect('1', 'refresh');
}

What's is missing?
#2

[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());
#3

[eluser]hccoder[/eluser]
Hello,

If you wanna refresh current page try this:

function set_language(){
redirect(uri_string(), 'refresh');
}

edit: im too slow Smile
#4

[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(){
redirect(uri_string());
}


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?
#5

[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')Wink;
}
#6

[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')Wink;
}[/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?
#7

[eluser]hccoder[/eluser]
I don't know Smile, but I think won't lose anything if You try it Smile




Theme © iAndrew 2016 - Forum software by © MyBB