更改搜索项的URL和在代码点火器中的路由

问题描述 投票:0回答:1

我想使用Codeigniter路由更改URL:

这是我的网址:

home/search?location=BD

home/search?location=BD&category[]=123

home/search?location=BD&category[]=123&category[]=124&category[]=125

像上面的URL,但是我想用这个路由

home/BD

home/BD/123

home/BD/123+124+125 

home/BD/123/124/125

我的[[route.php:

$route['home/(:any)/(:any)'] = 'home/search/$1';
route.php页面上我怎么了?
php codeigniter url routing
1个回答
0
投票
尝试在(.+)上使用route.php模式,$1将包含location值(BD),并且$2将包含home/BD/ url之后的所有参数:

$route['home/(:any)/(.+)'] = 'home/search/$1/$2';

(.+)模式很有用,如果您不知道要传递多少个参数,它将允许您捕获所有这些参数。也许您应该使用&代替网址中的+符号,因为默认情况下+符号可能是不允许的:

home/BD/123&124&125

然后您可以在控制器上展开类别:

public function search($location = '', $categories = '') { if (!empty($categories)) { $categories = explode('&',$categories); } ... }

© www.soinside.com 2019 - 2024. All rights reserved.