CodeIgniter Forums
Refreshing the current site - 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: Refreshing the current site (/showthread.php?tid=12091)



Refreshing the current site - El Forum - 10-06-2008

[eluser]grobald[/eluser]
Hello

Is there a function for refreshing the same view/page/site?

Code:
if(!$this->auth->is_logged_in()) {
        $this->session->set_userdata('message', $this->lang->line('error_not_logged_in'));
            //$this->refresh(); ?????*/

            //exit;
        }
i tried the search but i didn't find anything
thx for help


Refreshing the current site - El Forum - 10-06-2008

[eluser]xwero[/eluser]
In the url helper there is the redirect function which is what you need


Refreshing the current site - El Forum - 10-06-2008

[eluser]grobald[/eluser]
thx for the fast reply. i know this function, but what if i dont know where to redirect? for instance i have a site which is called like <?=baseurl?>user/antonio and i just want to reload this page. At the time i want to reload the page i do not have antonio set.

thx


Refreshing the current site - El Forum - 10-06-2008

[eluser]xwero[/eluser]
you can do
Code:
redirect(substr($this->uri->uri_string(),1));



Refreshing the current site - El Forum - 10-06-2008

[eluser]grobald[/eluser]
i found a solution:
Code:
function add_rating($redirect)
    {
        // Check for auth
        if(!$this->auth->is_logged_in()) {
            $this->session->set_userdata('message', $this->lang->line('error_not_logged_in'));
            redirect('/user/'.substr($redirect, 0));
        }
i had to pass the actual username to the add function and than add to the redirect url

thx for help


Refreshing the current site - El Forum - 10-06-2008

[eluser]grobald[/eluser]
But there is still a problem with refreshing the page. Its weird that there is no function which you can use just for refreshing the same page. For instance i have a error messag with a clos link. After clicking on that link it should just reload the same page without passing the current position in the application.
Code:
function reset_message()
    {
        $this->session->unset_userdata('message');
        redirect(to the current page...);
    }
Or do you have some clues for that.?


Refreshing the current site - El Forum - 10-06-2008

[eluser]xwero[/eluser]
uri_string gives you the the page that is going the be loaded so if you don't go to some other controller for the authentication process you can use that function.
If you do the authentication in another controller and you want to go back to the page you filled in the authentication form you need to fetch the page before sending the post data to the authentication controller.
The 1.7 url helper has a uri_string function you can use to populate a hidden field named current_page for example. But you can add the function yourself.
Code:
function uri_string()
    {
        $CI =& get_instance();
        return $CI->uri->uri_string();
    }



Refreshing the current site - El Forum - 10-06-2008

[eluser]Dready[/eluser]
Hello

Perhaps :
Code:
redirect(__CLASS__.'/'.__FUNCTION__);

? (valid for any PHP >= 4.3


Refreshing the current site - El Forum - 10-06-2008

[eluser]Sarre[/eluser]
Code:
function add_rating()
    {
        // Check for auth
        if(!$this->auth->is_logged_in()) {
            $this->session->set_userdata('message', $this->lang->line('error_not_logged_in'));
            $this->add_rating();
        }
?