2010-05-19 53 views
0

如何使工作的网址是这样的:example.com/controller/method?id=1&cat=2结合友好的URL和查询字符串

+0

是否有任何理由不能通过URI段传递“id”和“cat”?例如,example.com/controller/method/1/2或example.com/controller/method/id/1/cat/2? – 2010-05-19 19:23:26

+0

也许是因为这个url不是由我创建的,还有什么其他的原因可以呢? – 2010-05-19 21:34:57

+0

dynback.com ...我们不知道。这就是我们问的原因。 – 2010-05-20 02:59:22

回答

5

它是在你的config.php文件设置$config['enable_query_strings'] = TRUE;可能(如DamienL回答)。我刚刚尝试了一个新的CodeIgniter安装from here

但是,它似乎必须至少有2个变量(用“&”分隔)才能起作用。

下面是我做的步骤这一点:

在config.php,我改变$config['base_url']到相应的目录,并设置$config['enable_query_strings'] = TRUE;

在我创建了以下类控制器目录:

class Testing extends Controller { 

    function Testing() 
    { 
     parent::Controller(); 
    } 

    function index() 
    { 
     $this->load->view('welcome_message'); 
    } 
} 

/* End of file testing.php */ 

/* Location: ./system/application/controllers/testing.php */ 

我可以再与查询字符串访问索引功能,但前提是有2个或多个变量是这样的:

本地主机/ CodeIgniter_1.7-1.2/index.php文件/测试/索引?ID = 123 &猫= ABC

如果你确实需要这两个段基和查询基于字符串的方法,但只需要一个特定的查询字符串中的变量,我想你可以添加第二个“虚拟”变量,并忽略它。

+0

你的选择是这样的: http://127.0.0.1/critic/index.php?c=testing&m=index&some=1 | 但我需要这个: http://127.0.0.1/critic/index.php/testing/index?some=1 – 2010-05-21 18:17:37

+0

@ dynaback.com:为什么-1?启用查询字符串后,您可以执行127.0.0.1/critic/index.php/testing/index?some=1。我会编辑我的答案,以澄清 – 2010-05-21 18:37:40

+0

我有404这个。当我设置该选项时,只有段和唯一的查询字符串变得有效。但不是在一个网址。 – 2010-05-21 19:11:56