用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6266|回复: 13
收起左侧

[HELP] hooks文件夹中redirect用法

[复制链接]
发表于 2010-11-10 14:11:45 | 显示全部楼层 |阅读模式
hooks文件夹中写了一个类,类中使用redirect()函数,redirect()之前所有处理没问题,但是到了这个函数,就不能跳转到controller的函数中去,
页面出现的错误提示是,找不到URL
发表于 2010-11-10 14:36:50 | 显示全部楼层
贴出你的代码
 楼主| 发表于 2010-11-10 14:41:58 | 显示全部楼层
class Auth
{
    function check()
    {
        $ci =& get_instance();
        var_dump($ci);
        $class = $ci->uri->segment(1);
        $method = $ci->uri->segment(2);
        if (!$ci->session->userdata('logged_in')) {
            if (!($class == 'auth' && in_array($method, array('login', 'do_login')))) {
                redirect('checkbox/a_index');
            }
        }
    }
发表于 2010-11-10 14:46:10 | 显示全部楼层
redirect(site_url('checkbox/a_index'));
用路径的时候都要用完整路径,谢谢
 楼主| 发表于 2010-11-10 14:52:51 | 显示全部楼层
不是把redirect里面是加 (controller/方法名字)
刚才看了redirect函数的说明
function redirect($uri = '', $method = 'location')
{
        switch($method)
        {
                case 'refresh'        : header("Refresh:0;url=".site_url($uri));
                        break;
                default                : header("Location: ".site_url($uri));
                        break;
                }
                exit;
        }
}
不用特意加site_url
说明一下,我用的1.6.3版本的
发表于 2010-11-10 14:56:31 | 显示全部楼层
本帖最后由 jeongee 于 2010-11-10 15:01 编辑

我测试了一下是可以的,我想是你的判断逻辑有问题,导致无限跳转了
PHP复制代码
 
if (!($class == 'auth' && in_array($method, array('login', 'do_login')))) {
                redirect('checkbox/a_index');
            }
 
复制代码


改成
PHP复制代码
 
if (!(($class == 'auth') && in_array($method, array('login', 'do_login')))) {
                redirect('checkbox/a_index');
            }
 
复制代码

试试
 楼主| 发表于 2010-11-10 15:00:07 | 显示全部楼层
哪个地方??
发表于 2010-11-10 15:02:33 | 显示全部楼层
$class == 'auth' 用括号括起来
 楼主| 发表于 2010-11-10 15:08:39 | 显示全部楼层
好像不是这个判断的地方,加不加括号,都能走到redirect('checkbox/a_index');之前
就是redirect('checkbox/a_index')跳转以后的事情,地址栏里面都出现了
http://192.168.1.173/main/check/a_index,就是不能访问controller中的函数
这个是不是哪里设置的问题
 楼主| 发表于 2010-11-10 16:02:32 | 显示全部楼层
.htaccess
可能是用了这个文件的原因

本版积分规则