组合友好的URL和查询字符串 [英] Combine friendly url and query string

查看:122
本文介绍了组合友好的URL和查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

$ config ['enable_query_strings'] = TRUE; 由于 DamienL 回答)。我刚刚试用了一个新的CodeIgniter安装从这里



但是,它似乎必须至少有两个变量(用&分隔)才能正常工作。 >

以下是我花费的步骤:



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



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

  
$ b function testing()
{
parent :: Controller();
}

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

/ *文件结束testing.php * /

/ *位置:./system/application/controllers/testing。 php * /

然后,我可以使用查询字符串访问索引函数,或更多的变量:


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


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


How to make a working url like this: example.com/controller/method?id=1&cat=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:

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.

这篇关于组合友好的URL和查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆