Codeigniter/Pyrocms中的基本路由

Codeigniter/Pyrocms中的基本路由,codeigniter,routing,pyrocms,Codeigniter,Routing,Pyrocms,我在pyrocms中有一个称为event的模块,因为我无法将其称为event,因为已经存在events类 不过,我希望使用localhost/events url来引导事件模块,因此我尝试在event/config/routes.php中设置一个路由 用这条线 $route['events/(:any)?'] = 'event/$1'; 但这不起作用-我做错了什么?我认为问号可能会干扰路由,所以应该是: $route['events/(:any)'] = 'event/$1';

我在pyrocms中有一个称为event的模块,因为我无法将其称为event,因为已经存在events类

不过,我希望使用localhost/events url来引导事件模块,因此我尝试在event/config/routes.php中设置一个路由

用这条线

$route['events/(:any)?']        = 'event/$1';

但这不起作用-我做错了什么?

我认为问号可能会干扰路由,所以应该是:

$route['events/(:any)'] = 'event/$1';

您需要指向类/方法ie:

$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){}

它会抛出什么错误?你有一个事件控制器吗?如果没有对错误的描述,千万不要说不起作用。你是不是收到了404,致命错误,死亡蓝屏?谁知道如果你只是说没用。这没用: