php 如何在 CodeIgniter 中重定向页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10861164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:14:50  来源:igfitidea点击:

How to redirect a page in CodeIgniter?

phpcodeigniterredirect

提问by Jaydeepsinh Jadeja

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?

如果某些条件返回 true,我想重定向页面。我不知道该怎么做。谁能给我举个例子?

Or is there any way to accomplish this?

或者有什么办法可以做到这一点?

回答by Yan Berk

Use the redirect()function from the URL Helper.

使用redirect()从功能网址助手

EDIT: load the url helper:

编辑:加载 url 助手:

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

回答by Logan

Use redirect() helper function.

使用 redirect() 辅助函数。

Example :

例子 :

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

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

回答by Jone

Try this code after your ifstatement

在你的if语句之后试试这个代码

redirect(site_url('/index'));

I hope that is helpful for you.

我希望这对你有帮助。

回答by Arun Yokesh

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

or

或者

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

or

或者

redirect('controller/function');