Codeigniter/Pyrocms中的基本路由

Jak*_*kob 0 routing codeigniter pyrocms

我在pyrocms中有一个模块,它被称为事件,因为由于已经存在的事件类,我无法将其称为事件

我想让localhost/events url引导到事件模块,所以我尝试在event/config/routes.php中设置一个路由

用这条线

$route['events/(:any)?']        = 'event/$1';
Run Code Online (Sandbox Code Playgroud)

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

Phi*_*lip 6

你需要指向类/方法,即:

$route['events/(:any)'] = 'class/method/$1';
Run Code Online (Sandbox Code Playgroud)

(:any)并且(:num)是通配符.您可以使用自己的模式.

举个例子(用于演示目的):

// www.mysite.com/search/price/1.00-10.00
$route['search/price/(:any)'] = 'search/price/$1';
Run Code Online (Sandbox Code Playgroud)

$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 
}
Run Code Online (Sandbox Code Playgroud)

所以现在路线变成了

$route['search/price/(\d.+)-(\d.+)'] = 'search/price/$1/$2';
Run Code Online (Sandbox Code Playgroud)

调节器

public function price($start_range, $end_range){}
Run Code Online (Sandbox Code Playgroud)