2012-05-08 50 views
0

我有一个模块中pyrocms其称为事件,因为我不能把它称为事件由于已经存在的事件类基本的路由

我想有本地主机/事件网址导致事件模块虽然如此,我已经试过这条线

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

设置在事件/配置/ routes.php文件

的路线,但还是不行 - 我究竟做错了什么?

+0

它抛出了什么错误?你有事件控制器吗? – Seabass

+0

如果没有描述出了什么问题,千万不要说“不起作用”。你是否遇到了404致命错误,蓝屏死机?谁知道你是否说“不起作用”。没用的 :) –

回答

1

我觉得问号可以与路由地干扰,所以它应该是:

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

您需要将指向类/方法,即:

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