2016-06-15 5 views
0

Ich konvertiere eine CakePHP2-Suchfunktion nach CakePHP3. Ich konvertiere Post-Parameter, um Parameter zu erhalten. Ich bekomme die richtigen Parameter als Abfragezeichenfolge in der Adressleiste, aber wenn ich auf die Variablen in der for-Schleife unten zugreife, bekomme ich keine Ausgabe. Ich kann nicht sehen, was ich falsch mache, und ich kann die Antwort in den Dokumenten nicht finden.kann keine GET-Parameter für eine cookephp3-Suchfunktion erhalten

Wie bekomme ich die GET Parameter in der foreach Schleife unten 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 

Antwort

0

Das funktionierte

foreach($this->request->query as $param_name => $value): 

       if ($param_name=='lastname') $searchLastName =$value; 
       if ($param_name=='firstname') $searchFirstName =$value; 


      endforeach;