2013-05-10 43 views
2

我傳遞方法的搜索數據得到的是:CakePHP的如何從數據獲取提交

example.com/posts/?q=foo 

我想retrive在控制器這個數據這樣做:

$this->params['q']; 

但沒有工作。訪問查詢字符串

+0

'$ Q = $ _GET [ 'Q']'; – 2013-05-10 03:08:24

回答

1

CakePHP的specifice功能:

$this->request->query['q']; 

參考:Link

+0

這是完美的..感謝兄弟。 – 2013-05-10 03:25:05

+0

不客氣... – 2013-05-10 03:26:10

2

看起來你使用的是CakePHP 1.3。如果提交的是用蛋糕的形式助手進行的,它應該是這樣..

$this->params['data']['q'] 

,或者讓你,如果你明確寫的形式自己的HTML代碼,

$this->params['url']['q'] 
+0

我使用蛋糕2.x – 2013-05-10 03:23:13

1

CakePHP有simple helpers訪問參數。


對於GET參數可以使用:

/users/search?age=23 
$this->request->query['age']; // 23 

對於POST參數可以使用:

$this->request->data('age'); // 23