在codeigniter中更改搜索项目的网址和路由 [英] change search item url and routing in codeigniter
问题描述
我想使用Codeigniter路由更改URL:
这是我的网址:
home / search?location = BD
home / search?location = BD& category [] = 123
home / search?location = BD& amp; ; category [] = 123& category [] = 124& category [] = 125
但我想使用$ p $
home / BD
home / BD / 123 $ b来路由此网址
$ b home / BD / 123 + 124 + 125
或
home / BD / 123/124/125
我的 route.php :
$ route ['home /(:any)/(:any)'] ='home / search / $ 1';
route.php
的问题是什么
尝试在(。+)
模式上使用您的 route.php
, $ 1
将包含位置
值( BD
)和 $ 2
将包含 home / BD /
网址:
$ route ['home /(:any)/ (。+)'] ='home / search / $ 1 / $ 2';
(。+)
模式非常有用如果您不知道要传递多少个参数,则可以捕获所有这些参数。也许您应该使用&
代替url上的 +
符号,因为
home / BD / 123& 124& 125 $ b是默认情况下不允许使用+
符号$ b
然后,您可以爆炸控制器上的类别:
< pre class = lang-php prettyprint-override>
公共函数搜索($ location ='',$ categories ='')
{
if(!empty($ categories )){
$ categories = explode('&',$ categories);
}
...
}
I want to change the URL with Codeigniter routing:
here is my url:
home/search?location=BD
home/search?location=BD&category[]=123
home/search?location=BD&category[]=123&category[]=124&category[]=125
like above url but I want to routing this url with
home/BD
home/BD/123
home/BD/123+124+125
or
home/BD/123/124/125
My route.php:
$route['home/(:any)/(:any)'] = 'home/search/$1';
What is my problem in route.php
page?
Try to use a (.+)
pattern on your route.php
, the $1
will contain the location
value (BD
) and the $2
will contain every parameters past the home/BD/
url :
$route['home/(:any)/(.+)'] = 'home/search/$1/$2';
The (.+)
pattern is useful if you don't know how many parameters are being passed, it will allow you to capture all of them. And maybe you should use &
in place of the +
sign on your url since the +
sign is probably disallowed by default :
home/BD/123&124&125
Then you could explode the categories on the controller :
public function search($location = '', $categories = '')
{
if (!empty($categories)) {
$categories = explode('&',$categories);
}
...
}
这篇关于在codeigniter中更改搜索项目的网址和路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!