2012-04-17 68 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.。所以如果你想要这个工作,你必须定义所有的路由参数。