如何在 Kohana 3 中获取操作 URL?

发布于 2024-12-13 04:06:21 字数 295 浏览 6 评论 0原文

是否有官方方法或帮助程序可用于获取视图中操作的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空‖城人不在 2024-12-20 04:06:21

1.使用路由名称获取URI:

 $uri = Route::get('routename')
     ->uri(array(
           'controller' => $controller, 
           'action' => $action
          ));

2a。使用主路由获取URI:

 $uri = Request::instance()
     ->uri(array(
           'controller' => $controller,
           'action'     => $action
 ));

2b。与当前路线相同:

 $uri = Request::current()
     ->uri(array(
           'controller' => $controller,
           'action'     => $action
 ));

2cRequest::uri() 默认使用当前路由参数,因此如果您只想更改 action (或 id 等),您可以跳过当前参数

 $uri = Request::instance() // or Request::current()
     ->uri(array(
           'action'     => $action
 ));

仅传递操作,我们要求Request使用其当前值($this->controller code> 为控制器名称, $this->directory 用于目录等)

PS。阅读本文

聚苯硫醚。在 Kohana v3.2 中,Request::uri() 调用返回一个当前 URI,因此您需要调用 Request::current ()->route()->uri(...);

1.Get URI using route name:

 $uri = Route::get('routename')
     ->uri(array(
           'controller' => $controller, 
           'action' => $action
          ));

2a.Get URI using main route:

 $uri = Request::instance()
     ->uri(array(
           'controller' => $controller,
           'action'     => $action
 ));

2b.The same with current route:

 $uri = Request::current()
     ->uri(array(
           'controller' => $controller,
           'action'     => $action
 ));

2c. Request::uri() uses current route params by default, so if you want to change only action (or id etc), you can skip current params:

 $uri = Request::instance() // or Request::current()
     ->uri(array(
           'action'     => $action
 ));

Passing only an action, we ask Request 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 call Request::current()->route()->uri(...);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文