为什么CodeIgniter中的重定向功能不起作用? [英] Why redirect function in CodeIgniter not working?

查看:108
本文介绍了为什么CodeIgniter中的重定向功能不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题。我使用CI已超过2年了,这是我第一次发现这种问题。我发现重定向功能无法正常工作。我已经在autoload.php中加载了url帮助器。

I have a really weird problem. I have been using CI for more than 2 years and it's the first time I found this kind of problem. I found that the redirect function is not working properly. I already load the url helper in autoload.php.

$autoload['helper'] = array('url','html','form','file');

我要做的是将用户重定向到控制器(如果他们呼叫管理员)。

What I want to do is to redirect the users to a controller if they call admin controller.

class Admin extends CI_Controller {
   function index(){
      redirect('secure');
   }
}

但是发生的是页面被重定向到base_url。我尝试添加带有刷新或位置的重定向的第二个参数,但结果是相同的。它还发生在其他控制器中的所有重定向功能上。谁能告诉我这个问题发生的原因吗?

But what happen is the page redirected to the base_url. I've tried adding the second parameter of redirect with refresh or location but the result is just the same. It also happens to all redirect function in other controller. Can anyone tell me what the cause of this problem to happen?

编辑:
有关可能对发现问题有帮助的其他信息,在这里我将

For additional information that might be helpful for finding the problem, here I put the code of the routes.php.

$route['default_controller'] = "frontpage";
$route['404_override'] = 'errors/page_missing';
$route['admin'] = 'secure';


推荐答案

我刚刚发现问题是由在我的助手中起作用。碰巧的是,我在帮助器中使用了site_url()函数,CI已使用它。我用另一个名称替换了该函数,现在重定向工作正常。不过,我不知道它如何影响重定向功能。感谢任何试图帮助我的人。

I just figured out that the problem is caused by a function in my helper. By coincident, I use site_url() function in the helper, which is already used by the CI. I replace that function with another name and now the redirection is working perfectly. I don't know how it can affects the redirect function, though. Thanks for anybody tried to help me.

这篇关于为什么CodeIgniter中的重定向功能不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆