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

[已解决] 关于_remap的参数问题

[复制链接]
发表于 2009-11-13 23:45:33 | 显示全部楼层 |阅读模式
首先我是刚学ci 才两天的人,现在在看它的手册,边看边练习,现在遇到一个不解的问题,请指教,第一次发帖,见笑:

先引用手册内容:


你可以这样理解上面的方法:当 $method 等于你定义的参数时程序执行一个特殊的操作,这里可以灵活运用。如下面的方法如果参数等于 c 就调用 comments,否则就调用用户输入的方法function _remap($method)
{
    if ($method == 'c')
    {
        $this->comment();
    }
    else
    {
        $this->$method();
    }
}

我的问题 如何处理传值的问题?

比如 我输入 http://localhost/CodeIgniter/index.php/blog/users/24

blog 是class   users 是方法    24 是值 那么我做以下代码:
    function _remap($method,$id){
        if($method != 'users'){
            $this->comment($id);
        }else{
            $this->$method($method,$id);
        }
    }   

    function users($id){
        echo '传值成功,admin 其值为:'.$id;
    }

    function comment($method,$id){
        echo '传值成功, '.$method.'其值为:'.$id;
    }

但是运行错误, 当我改成


    function _remap($method){
        if($method != 'users'){
            $this->comment();
        }else{
            $this->$method();
        }
    }   

    function users(){
        echo '传值成功,Joe其值为:';
    }

    function comment(){
        echo '传值成功, 其值为:';
    }

这样 ,它就显示正常了,但是,传过来的值怎么办?  谁可以指点一下,谢谢大家!
发表于 2009-11-14 00:21:16 | 显示全部楼层
_remap不允许传参数,详见system/codeigniter/CodeIgniter.php

解决办法:使用this->uri->segment(n)获得参数值
 楼主| 发表于 2009-11-14 03:13:43 | 显示全部楼层
谢谢,测试成功了!  但是还有一个问题,为什么参数不能是中文呢?

提示错误是:
An Error Was Encountered
The URI you submitted has disallowed characters.

字符不允许的话,如何更改?
发表于 2009-11-14 04:13:16 | 显示全部楼层
善用搜索

本版积分规则