rogman 发表于 2009-5-24 18:06:40

求助:CI路由问题

本帖最后由 rogman 于 2009-5-24 18:07 编辑

在写controller的时候:

我这样写:



class Blog extends Controller{

    function Blog()
    {
      parent::Controller();   
      $this->load->database();
    }
   
    function index()
    {
      //var_dump($this->db->query("SELECT * FROM users LIMIT 0,20"));
    }

    function edit($id)
    {
      //var_dump($this->db->query("SELECT * FROM users LIMIT 0,20"));
    }

}


当我这样访问的时候:

http://locahost/blog/edit/1   可以访问,

但是我这样访问:

http://locahost/blog/edit/1?somevar=5

就报错,这是什么原因?


404 Page Not Found

The page you requested was not found.

pader 发表于 2009-5-24 20:31:02

你试试
http://localhost/blog/edit/1/?somevar=5

Hex 发表于 2009-5-25 02:14:28

楼主的问题不是路由问题,是 GET 传参的问题,请参考 FAQ。

caincheung 发表于 2009-5-25 09:21:29

$config['enable_query_string'] = true;

Hex 发表于 2009-5-25 10:14:41

楼上的写法就不能使用 url 分段了。

rogman 发表于 2009-5-25 17:24:06

问题已经解决:

首先打开:
$config['enable_query_string'] = true;

然后再contrller构造器中加入:
parse_str($_SERVER['QUERY_STRING'], $_GET);       

即可。

感谢

Hex 发表于 2009-5-25 18:27:05

根本就不应该打开 $config['enable_query_string'] = true;
这样会影响 site_url 等函数。
请看 http://codeigniter.org.cn/forums/thread-692-1-1.html
页: [1]
查看完整版本: 求助:CI路由问题