1

在 KO 3.2 中是否有任何替代方法可以获取具有更改参数的 uri 作为 $this->request->uri($params) ?

例子:

//Kohana 3.1 ; current uri = articles/show/10 (<controller>/<action>/<id>)

$this->request->uri(array('id' => 11)); // return 'articles/show/11'

谢谢

4

1 回答 1

3

自 3.2 以来,没有“短”方法,因为现在$this->request->uri()返回当前 URI。$this->request->route()->uri()与您需要的所有参数一起使用:

$params  = array('id' => 11); // what params you want to change
$params += $this->request->param(); // current request params
$params += array(
    // note that $this->request->param() doesnt contain directory/controller/action values!
   'directory' => $this->request->directory(),
   'controller' => $this->request->controller(),
   'action' => $this->request->action(),
);
$uri = $this->request->route()->uri($params);

当然,您可以为此创建一个特殊的方法(例如$this->request->old_uri(array('id' => 11)))。

这是该 API 更改的问题链接

于 2012-05-23T06:07:27.617 回答