2010-10-28 93 views
0

我有這個路由在我的模塊的init.php中定義;kohana 3控制器動作參數的路由問題


Route::set('store', 'store/<store_id>(/<controller>(/<action>(/<id>)))', 
    array(
    'store_id' => '\d+' 
)) 
    ->defaults(array(
    'controller' => 'main', 
    'action'  => 'index', 
)); 

並且bootstrap.php中的默認路由仍然完好無損。


Route::set('default', '(<controller>(/<action>(/<id>)))') 
    ->defaults(array(
     'controller' => 'welcome', 
     'action'  => 'index', 
    )); 

我的Controller_Item類;


class Controller_Item extends Controller { 
    function action_category($category_id) 
    { 
     echo 'Category ID: '.$category_id; 
    } 
} 

http://mydomain.com/item/category/8使用
輸出:

Category ID: 8
它們指向正確的路由這是;
Controller_Item和方法 action_category(8)

問題是,當使用改性路線; http://mydomain.com/store/1/item/category/8 輸出:

Category ID: 1
它成爲 action_category(1)(它需要的參數從< STORE_ID>)

回答

2

獲取PARAM按名稱:

$id = $this->request->param('id');