Reputation: 662
I am converting a cakephp2 search function to cakephp3. I convert post parameters to get parameters . I get the correct parameters appearing as a query string in the address bar but when I access the variables in the for loop below I get no output. I cant see what I am doing wrong and I cant find the answer in the docs.
How do I get the GET parameters in the foreach loop below in cakephp3?
if ($this->request->is('post')) {
$filter_url['controller'] = $this->request->params['controller'];
$filter_url['action'] = $this->request->params['action'];
$filter_url['page'] = 1;
// for each filter we will add a GET parameter for the generated url
foreach($this->request->data as $name => $value){
if($value){
$filter_url[$name] = urlencode($value);
}
}
//Post params are now GET paramaters
return $this->redirect($filter_url);
}
debug($this->request->params['pass'] ); //outputs nothing
foreach($this->request->params['pass'] as $param_name => $value):
// debug($param_name);
// debug($value);
if ($param_name=='lastname') $searchLastName =$value;
if ($param_name=='firstname') $searchFirstName =$value;
endforeach;
//view
<?php echo $this->Form->create(); ?>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<td><?php echo $this->Form->input('firstname',['label' => 'FirstName']); ?></td>
<td><?php echo $this->Form->input('lastname',['label' => ' LastName']); ?></td>
<td> <?php //echo $this->Form->button('Submit Form', ['name'=>'search','type' => 'submit']); ?></td>
</tr>
</thead>
<?= $this->Form->button('Submit Form', ['name'=>'search','type' => 'submit']); ?>
<?= $this->Form->end() ?>
http://book.cakephp.org/3.0/en/controllers/request-response.html
Upvotes: 0
Views: 379
Reputation: 662
This worked
foreach($this->request->query as $param_name => $value):
if ($param_name=='lastname') $searchLastName =$value;
if ($param_name=='firstname') $searchFirstName =$value;
endforeach;
Upvotes: 0