2011-12-24 29 views
1

我有以下的bootstap.php路線行代碼的功能,我怎麼也得通參數的Kohana框架工作

Route::set('ads','ad/<ad>(/<affiliate>)') 
->defaults(array(
    'controller' => 'ads', 
    'action'  => 'index', 
)); 

那我怎麼樣了傳遞參數給function.Url爲localhost/index.php/ads /正在工作,但是當我給localhost/index.php/ads/12時,它顯示404錯誤。我知道如何訪問ads.php中的這些值,但我如何從url傳遞參數。

+0

請注意[此帖](http://stackoverflow.com/faq#signatures) – Dan 2011-12-24 13:12:05

回答

0

怎麼樣

Route::set('ads','ad/<ad>(/<affiliate>)', array('affiliate' => '.*')) 
->defaults(array(
    'controller' => 'ads', 
    'action'  => 'index', 
)); 
+1

它是可選的參數,如果我再通過它讀取值,否則缺省值將爲空 – 2011-12-24 13:13:33

1

不知道這是不是你的錯字(adsad),但與這條路線:

Route::set('ads','ads/<ad>(/<affiliate>)') 
->defaults(array(
    'controller' => 'ads', 
    'action'  => 'index', 
)); 

本地主機/ index.php文件/廣告/ 12有工作。在你的控制器,你可以通過訪問參數:

$this->request->param('ad'); 
相關問題