David
David

Reputation: 125

Codeigniter reset the function in URL

Not even sure the best way to describe this as a question so please feel free to change it.

I have Function mainfunction() in my controller that controls and loads a particular view via $this->load->view('mypage')

I have another function, Function updater() in the same controller whose only job is to run a one-line update query; it is called from a button on mypage. After the update query runs, I call mainfunction() from within updater(), so that after the user clicks the button, mypage is immediately reloaded and the user sees the result of his call to updater().

This appears to work on the surface: the updater() function runs the update and when it's finished I see mypage again, having been loaded from mainfunction(). The problem is that the URL is still pointing to /updater, with the effect that if the user hits a page refresh, it runs the update function again. How can I make it so that once the updater() function runs, it truly redirects the user back to /mainfunction in the URL?

Upvotes: 0

Views: 608

Answers (1)

Gulmuhammad Akbari
Gulmuhammad Akbari

Reputation: 2034

Do like this:

function mainFunction(){
 $this->load->view("view");
}

function updater(){
 //some code...
 redirect(base_url()."controller/mainFunction","refresh");
}

Upvotes: 1

Related Questions