2017-03-01 107 views
0

從Controller傳遞一個變量以在CakePHP3中查看時,出現問題。cakePHP3從控制器傳遞變量來查看

文件FincasController.php:我已經創建了一個公共方法來生成報告並能夠傳遞給我也創建的模板。

public function worklist() 
{ 

    $worklist = TableRegistry::get('Fincas'); 
    $query = $worklist 
     ->find() 
     ->select(['id', 'prov', 'municipio', 'paraje', 'poligono', 'parcela', 'f_ult_poda' , 'f_ult_recog' ]); 

    foreach ($query as $worklist) { 
      if ($worklist->f_ult_poda > $worklist->f_ult_recog) 
       debug($worklist); //it works fine 
     } 

    $this->set('finca', $this->$query); //I have tried also $this->$worklist 

} 

文件模板\ FINCAS \ worklist.ctp:

<?php debug($finca);?> 

非常感謝

回答

0

$query這胡斯塔一個變量,它不是你的FincasControllerõ. Why are you using $ this`屬性?

簡單

$this->set('finca', $query); 
+0

非常感謝您的快速反饋。 –