如何在CodeIgniter中重定向页面?

8
如果某个条件返回true,我希望能够重定向页面。我不知道如何做到这一点。有没有人可以为我提供一个例子呢?
或者还有其它实现方式吗?
4个回答

22

使用URL助手中的redirect()函数。

编辑: 加载url助手:

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

6

使用 redirect() 辅助函数。

示例:

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

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

2
在你的if语句后尝试这段代码。
redirect(site_url('/index'));

我希望这对你有所帮助。


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

或者

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

或者

redirect('controller/function');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接