将查询字符串映射到Kohana 3.2中的控制器方法参数

时间:2021-12-04 20:18:39

I want to setup my route so that url like word/startswith?prefix=ab maps to following code

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

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

Also could anyone tell me how can I get GET data in Kohana 3.2 controller? For the above scenario I can solve it by,

也有人能告诉我如何在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.
        }
    }
}

1 个解决方案

#1


2  

Why don't you just use $this->request->query('prefix') ?

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

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

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

#1


2  

Why don't you just use $this->request->query('prefix') ?

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

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

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