2012-04-17 67 views
0

我想在循環內的視圖內添加簡單的鏈接在kohana。Kohana 3.2路線::得到

這裏是我的代碼有:

echo HTML::anchor(Route::get('parent')->uri(array('id' => $parent->id)), HTML::chars($parent->email)) 

現在這個返回一個鏈接到根,因爲

Route::get('parent')->uri(array('id' => $parent->id) 

返回一個空字符串。

現在,如果如果我修改我的路線::到:

Route::get('parent')->uri(array(
         'controller' => 'parent' , 
         'action'  => 'index' , 
         'id'   => $parent->id)) 

我得到正確的鏈接。

問題:爲什麼Kohana的是沒有能夠得到正確的鏈接知道,在我的引導,我有以下幾點:

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

這:路線::獲得(「父」)返回:

: object(Route) = 
    _callback: undefined = NULL 
    _uri: string = "(<controller>(/<action>(/<id>)))" 
    _regex: array = 
    _defaults: array = 
    controller: string = "parent" 
    action: string = "index" 
    _route_regex: string = "#^(?:(?P<controller>[^/.,;?\\n]++)(?:/(?P<action>[^/.,;?\\n]++)(?:/(?P<id>[^/.,;?\\n]++))?)?)?\$#uD" 

回答

1

由於Kohana 3.2 doc(http://kohanaframework.org/3.2/guide/api/Route#uri)Route::uri() method Generates a URI for the current route based on the parameters given.。所以如果你想要這個工作,你必須定義所有的路由參數。