Kohana 3 专家,处理请求参数 Route::set()、request->params() in K3 v. >= 3.1
最初在 Kohana 3 中,您可以通过 URL 传递控制器操作参数/参数,如下所示:
http:/website/controller/actionname/param1/param2/.../paramX
并通过简单地定义操作来处理它,如下所示:
public action_actionname($params)
{
$params_array = explode("/", $params);
//you can now use $params_array[0], $params_array[1], ...
}
现在看来,自 v3.1 以来,他们决定弃用此功能(这里是 link),它应该在 v3.2 中被删除
而且他们似乎希望你使用 Route ::Set() 和 request->param() 方法。这是否意味着每次在控制器中定义方法/操作时,都必须为应用程序中其他位置的每个参数定义单独的路由? 谁能用简单的术语向我解释一下这是如何工作的。为了简单地调用函数而完成所有这些工作似乎有很多不必要的“麻烦”。
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 explain 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您应该考虑在路由中使用正则表达式参数来覆盖默认匹配行为...我通常使用它来捕获一个 KO3“参数”中的多个 URL 参数。示例:
现在在您的控制器中,
$this->request->param("param_list")
将等于与正则表达式.*
匹配的任何内容,这意味着您可以捕获URL 的其余部分就像您所希望的那样,带有斜杠等等!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:
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!