Codeigniter中的路由问题

时间:2018-06-20 11:53:08

标签: codeigniter url routes codeigniter-3

URL:example.com/bikes/cityname/makename

我的路由配置如下

$route['bikes']  = 'bikes/index';
$route['bikes(/:any)'] = 'bikes/bike_details$1';
$route['bikes/(:any)/(:any)'] = 'bikes/index';

我有这个控制器

public function index($city='',$make='')
{
 echo $city."--".$make;
 // these two are empty

我在下面尝试过,给我错误

 public function index($city,$make)
 {
  // not working

这对双方都应该起作用

example.com/bikes/cityname/makename

example.com/bikes/

1 个答案:

答案 0 :(得分:0)

希望这对您有帮助:

route.php应该是这样的:

$route['bikes/index']  = 'bikes/index';
$route['bikes/(:any)'] = 'bikes/$1';
$route['bikes/(:any)/(:any)'] = 'bikes/$1/$2';

更多信息:https://www.codeigniter.com/user_guide/general/urls.html