我在 pyrocms 中有一个模块,它被称为事件,因为由于已经存在的事件类,我不能将它称为事件
我想让 localhost/events url 指向事件模块,所以我尝试在 event/config/routes.php 中设置路由
用这条线
$route['events/(:any)?'] = 'event/$1';
但这不起作用 - 我做错了什么?
我在 pyrocms 中有一个模块,它被称为事件,因为由于已经存在的事件类,我不能将它称为事件
我想让 localhost/events url 指向事件模块,所以我尝试在 event/config/routes.php 中设置路由
用这条线
$route['events/(:any)?'] = 'event/$1';
但这不起作用 - 我做错了什么?
您需要指向类/方法,即:
$route['events/(:any)'] = 'class/method/$1';
(:any)
并且(:num)
是通配符。您可以使用自己的模式。
举这个例子(用于演示目的):
// www.mysite.com/search/price/1.00-10.00
$route['search/price/(:any)'] = 'search/price/$1';
$1
等于通配符(:any)
所以你可以说
public function price($range){
if(preg_match('/(\d.+)-(\d.+)/', $range, $matches)){
//$matches[0] = '1.00-10.00'
//$matches[1] = '1.00'
//$matches[2] = '10.00'
}
//this step is not needed however, we can simply pass our pattern into the route.
//by grouping () our pattern into $1 and $2 we have a much cleaner controller
//Pattern: (\d.+)-(\d.+) says group anything that is a digit and fullstop before/after the hypen( - ) in the segment
}
所以现在路线变成了
$route['search/price/(\d.+)-(\d.+)'] = 'search/price/$1/$2';
控制器
public function price($start_range, $end_range){}
我认为问号可能会干扰路由,所以应该是:
$route['events/(:any)'] = 'event/$1';