2016-07-26 26 views
0

使用CakePHP3,我有一個帶有GET方法的搜索表單。嘗試獲取URL參數似乎不起作用。我做如下:CakePHP3中的參數URL

if(isset($this->request->params['text'])){ 

     // the code ... 
    } 

搜索表單的行動已經確定的路線:

$routes->connect('/search', [ 
    'controller' => 'Top', 
    'action' => 'index' 
], 
[ 
    '_name' => 'search' 
]); 

如何解決這一問題?

+0

你有沒有試過這種? var_dump($ this)或var_dump($ this-> request-> params ['text']) – DeFeNdog

+1

** [請求與響應對象>查詢字符串參數](http://book.cakephp.org/3.0/en/ controllers/request-response.html#query-string-parameters)** – ndm

+0

'var_dump($ this-> request-> params ['text'])'returns'NULL'。雖然,我的網址顯示'localhost/app/search?text = toto'。 – sk001

回答

1

你可以做這樣的事情FO獲取查詢字符串($ _ GET)參數

if(isset($this->request->query['text'])){ 
     // the code ... 
} 
+0

看起來像' isset()'不能用函數作爲參數調用。我可以這樣做: '$ text = $ this-> request-> query ['text'];如果(isset($ text)){/ * ... * /}' – sk001