0

I'm trying to add simple links in kohana inside a view inside a loop .

Here is the code i have :

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

Now this return a link to root because

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

returns an empty string .

Now if If i modify my Route::get to :

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

I get the correct link .

Question : Why Kohana is not able to get the correct link knowing that in my bootstrap i have the following :

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

And that : Route::get('parent') returns :

: 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"
4

1 に答える 1

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.ます。したがって、これを機能させたい場合は、すべてのルート パラメータを定義する必要があります。

于 2012-04-18T06:52:22.387 に答える