问题
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?
回答1:
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);
}
...
}
来源:https://stackoverflow.com/questions/61006159/change-search-item-url-and-routing-in-codeigniter