开发者

Kohana 3 experts, handling request arguments Route::set(), request->params() in K3 v. >= 3.1

Originally in Kohana 3 you were able to pass controller action arguments/parameters through URL as in:

http:/website/controller/actionname/param1/param2/.../paramX

and handle it by simply defining the action as in:

public action_actionname($params)
{
   $params_array = explode("/", $params); 
   //you can now use $params_array[0], $params_array[1], ...
}

Now it seems that since v3.1 they decided to deprecate this feature (here is the link) and it should be eliminated in v3.2

And it seems they want you to use Route::Set() and request->param() methods instead. Does this mean that every time you define a method/action in a controller, you have to define a separate routing for each argument someplace else in your application? Can anyone please exp开发者_如何学Golain to me how this works in simple terms. It just seems like a lot of unnecessary "hassle" to do all of that to simply call a function.


Maybe you should consider using the regex param in your route to override the default matching behavior... I typically use this to capture multiple URL parameters in one KO3 "param". Example:

Route::set('route1', '<controller>/<action>(/<param_list>)', array('param_list'=>'.*'))
->defaults(array(
    'controller'   => 'my_default_controller',
    'action'       => 'my_default_index'
));

Now in your controller, $this->request->param("param_list") will equal whatever matches the regex expression .* which means you can capture the rest of the URL just like you were hoping, with slashes and all!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜