结合友好的 url 和查询字符串

发布于 2024-09-02 01:06:13 字数 76 浏览 1 评论 0原文

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

How to make a working url like this: example.com/controller/method?id=1&cat=2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

层林尽染 2024-09-09 01:06:13

可以通过在 config.php 文件中设置 $config['enable_query_strings'] = TRUE; (如 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

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

It is possible by setting $config['enable_query_strings'] = TRUE; in your config.php file (As DamienL answered). I just tried with a fresh CodeIgniter installation from here.

However, it appears there must be at least 2 variables (separated with a "&") for it to work.

Here are the steps I took to make this happen:

In config.php, I changed $config['base_url'] to the appropriate directory and set $config['enable_query_strings'] = TRUE;

In the controllers directory I created the following class:

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 */

I can then access the index function with a query string, but only if there are 2 or more variables like this:

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

If you absolutely need both the segment-based and query string-based approaches, but only need one variable in a particular query string, I suppose you could add a second "dummy" variable and just ignore it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文