使用URI段在CodeIgniter中执行GET请求

时间:2013-08-07 03:26:52

标签: codeigniter codeigniter-url

如果我有这样的表格:

<form method="GET">
    <input type="text" name="search" />
</form>

如果我提交,则会生成如下网址:
http://exmaple.com/search/results?search=text1+text2

现在这不适用于我的代码。如何使其使用URI细分,因此生成的网址如下所示:http://exmaple.com/search/results/search/text1+text2

更多澄清 换句话说,我想要的是当我使用简单的html表单执行get请求时,它生成的url看起来像codeigniter的URL,即example.com/class/function/param1/param2
而不是example.com/class/function?param1&param2

2 个答案:

答案 0 :(得分:1)

in your codeigniter config file $config['enable_query_strings'] is set to false, so the url looks like http://example.com/search/results/search/text1+text2

if you want url like http://example.com/search/resutls?search=text1+text2 then set $config['enable_query_strings'] to true;

答案 1 :(得分:0)

使用codeigniter路由可以实现http://exmaple.com/search/results/search/text1+text2

将此信息放入您的路线中

$route['search/results/search/(:any)'] = "search/results?search=$1"