AnN*_*LaI 17 cakephp cakephp-1.3
如何在CAKEPHP中访问GET请求?
如果我在URL中传递变量
http://samplesite.com/page?key1=value1&key2=value2
Run Code Online (Sandbox Code Playgroud)
我应该使用$ _GET或$ this-> params来获取控制器中的值吗?CAKEPHP的标准是什么?
Cod*_*der 24
在CakePHP 2.0中,这似乎已经改变了.根据您可以访问的文档$this->request->query或$this->request['url'].
// url is /posts/index?page=1&sort=title
$this->request->query['page'];
// You can also access it via array access
$this->request['url']['page'];
Run Code Online (Sandbox Code Playgroud)
http://book.cakephp.org/2.0/en/controllers/request-response.html
dec*_*lan 22
在Cake中执行此操作的标准方法是使用$this->params.
$value1 = $this->params['url']['key1'];
$value2 = $this->params['url']['key2'];
Run Code Online (Sandbox Code Playgroud)
根据CakePHP的书,"$ this-> params的最常见用法是访问通过GET或POST操作传递给控制器的信息."
看到这里.
现在我们有了CakePHP 3; 你仍然可以$this->request->query('search')在你的观点中使用.
在CakePHP 3.5 +中你可以使用
$this->request->getQuery('search')
http://book.cakephp.org/3.0/en/controllers/request-response.html#request-parameters