【问题标题】:Map query string to controller method parameter in Kohana 3.2将查询字符串映射到 Kohana 3.2 中的控制器方法参数
【发布时间】:2012-01-04 22:13:01
【问题描述】:

我想设置我的路线,以便像word/startswith?prefix=ab 这样的网址映射到以下代码

class Controller_Word extends Controller_Mytemplate {
    public function action_startswith($fragment){
     /// Here $fragment should get "ab" value.
    }
}

还有谁能告诉我如何在 Kohana 3.2 控制器中获取 GET 数据?对于上述情况,我可以解决它,

class Controller_Word extends Controller_Mytemplate {
    public function action_startswith($fragment=null){
        if($fragment==null){
            /// set $fragment to $_GET['prefix'] but in Kohana way.
        }
    }
}

【问题讨论】:

  • 没有答案!甚至是评论! :(

标签: php model-view-controller kohana kohana-3


【解决方案1】:

你为什么不直接使用 $this->request->query('prefix') ?

http://kohanaframework.org/3.2/guide/api/Request#query

【讨论】:

  • +1 KO3.2 中的全新内容。此外我不知道Request 对象被分配在$this 中。你知道路线解决方案吗?因为我有更多的动作
  • 什么路由解决方案?从 3.2 开始,控制器中的 action_* 方法不应该有任何参数。使用 $this->request->param('parameter name') 代替。但在您的情况下,您需要一个查询字符串,它不是 uri 的一部分。所以 Request::query() 是要走的路。
猜你喜欢
  • 2014-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-20
  • 2012-11-15
  • 1970-01-01
相关资源
最近更新 更多