0

如何制作这样的工作网址:example.com/controller/method?id=1&cat=2

4

1 回答 1

5

可以通过$config['enable_query_strings'] = TRUE;在您的 config.php 文件中进行设置(正如DamienL回答的那样)。我刚刚尝试从这里安装新的 CodeIgniter 。

但是,它似乎必须至少有 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 个或更多这样的变量:

localhost/CodeIgniter_1.7-1.2/index.php/testing/index?id=123&cat=abc

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

于 2010-05-21T14:50:53.947 回答