2012-05-08 49 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){}