简体   繁体   中英

How to redirect a page in CodeIgniter?

I want to redirect a page if some condition returns true. I have no idea how to do this. Can any one provide me with an example?

Or is there any way to accomplish this?

Use the redirect() function from the URL Helper .

EDIT: load the url helper:

$this->load->helper('url');
if (condition == TRUE) {
   redirect('new_page');
}

Use redirect() helper function.

Example :

$this->load->helper('url');

if ($logged_in == FALSE)
{
     redirect('/login/form/', 'refresh');
}

Try this code after your if statement

redirect(site_url('/index'));

I hope that is helpful for you.

$this->load->helper('url');
redirect(base_url('controller/function'));

or

redirect(base_url().'controller/function');

or

redirect('controller/function');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM