无法通过数组变量形式控制器来查看以下代码 如果在控制器上打印,它显示“未定义的变量:数据”
public function report(){
$results=$this->Nodals->find()->toArray();
$this->set('data',$results);
print_r($data); die();}
答案 0 :(得分:0)
尝试像这样使用compact
。
public function report(){
$data=$this->Nodals->find()->toArray();
$this->set(compact('data'));
};
现在在您的视图中执行dd
,以检查data
变量是否发送到该视图。我假设您的视图文件为report.ctp
,所以在report.ctp
文件中写此行
<?php
dd($data);
?>
我希望它会有所帮助。
答案 1 :(得分:0)
$ data: $ this-> Nodals-> find()-> toArray();那么您需要将其存储在$ data变量或任何其他变量中
class Products(models.Model):
name=models.Charfield()
user=models.ForeignKey(User)
或
$results=$this->Nodals->find()->toArray();
$this->set('data',$results);
//data will be sent to the template which wrap the $result and in template you can access $reseult by using $data
print_r($results);
die();