结合友好的 url 和查询字符串
如何制作这样的工作网址: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以通过在 config.php 文件中设置
$config['enable_query_strings'] = TRUE;
(如 DamienL 回答)。我刚刚尝试从这里安装全新的 CodeIgniter。但是,似乎必须至少有 2 个变量(用“&”分隔)才能工作。
以下是我为实现此目的而采取的步骤:
在 config.php 中,我更改了
$config['base_url']
到适当的目录并设置$config['enable_query_strings'] = TRUE;
在控制器目录中我创建了以下类:
然后我可以使用查询字符串访问索引函数,但前提是有 2 个或更多变量,如下所示:
如果您绝对需要基于段和基于查询字符串的方法,但只需要特定查询字符串中的一个变量,我想你可以添加第二个“虚拟”变量并忽略它。
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:
I can then access the index function with a query string, but only if there are 2 or more variables like this:
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.