如何在 Kohana 3 中获取操作 URL?
是否有官方方法或帮助程序可用于获取视图中操作的 URL?
例如,当我处于 /controller/action0 视图中时,我喜欢获取 /controller/action1 的 URL。
我知道我可以使用以下代码,但我想知道它是否已经在 Kohana 的核心中。
function getControllerActionURL($controller,$action)
{
return URL::site(false,true).$controller."/".$action;
}
Is there an official method or helper that I can use to get an URL of an action in a view?
For example, I like to get a URL of /controller/action1 when I'm in a view of /controller/action0.
I know that I can use the following code, but I wonder if it is already in Kohana's core.
function getControllerActionURL($controller,$action)
{
return URL::site(false,true).$controller."/".$action;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1.使用路由名称获取URI:
2a。使用主路由获取URI:
2b。与当前路线相同:
2c。
Request::uri()
默认使用当前路由参数,因此如果您只想更改action
(或id
等),您可以跳过当前参数:仅传递
操作
,我们要求Request
使用其当前值($this->controller
code> 为控制器名称,$this->directory
用于目录等)PS。阅读本文。
聚苯硫醚。在 Kohana v3.2 中,
Request::uri()
调用返回一个当前 URI,因此您需要调用Request::current ()->route()->uri(...)
;1.Get URI using route name:
2a.Get URI using main route:
2b.The same with current route:
2c.
Request::uri()
uses current route params by default, so if you want to change onlyaction
(orid
etc), you can skip current params:Passing only an
action
, we askRequest
to use its current values ($this->controller
for controller name,$this->directory
for directory etc)PS. Read this.
PPS. In Kohana v3.2
Request::uri()
call returns a current URI, so you need to callRequest::current()->route()->uri(...)
;