I'd like to ask you how can I instead of $this->load->view('some_view.php') at the end of controller code, return user to page from where he invoked controller method? Simple return statement is not working.
ie.
public function someMethod($IDCustomer) {
$this->Some_modal->persist($IDCustomer);
// how to return to previous page instead of line after?
// i've used $this->load->view('someView.php');
}
here, i will show you both example to getting previous page url so, you can simply redirect on that page in codeigniter 3 application. first we will see user_agent library using referrer() for getting previous page url. $previous_url = $this->session->userdata('previous_url'); print_r($previous_url);
site_url() : Returns your site URL, as specified in your config file. The index. php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file.
Add base_url() in redirect function. Show activity on this post. redirect('Admin/index') was not working until I removed echo statement and print_r from the function. Your answer could be improved with additional supporting information.
This should help http://www.codeigniter.com/user_guide/libraries/user_agent.html
$this->load->library('user_agent');
if ($this->agent->is_referral())
{
echo $this->agent->referrer();
}
or straight PHP:
redirect($_SERVER['HTTP_REFERER']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With