如何在Views + cakephp中使用控制器变量

时间:2009-09-15 12:14:06

标签: mysql cakephp

我在控制器操作中使用了Query

   $report_attrid=$this->Report->find('all',array('conditions'=>array('Report.report_id'=>$report_id,'Report.user_id'=>$userId)));

 $submitters['Result']['submitters']=$this->Result->find('all',array('conditions'=>array('Result.form_id'=>$report_form_id)
 ,'group'=>array('Result.submitter_id')));


    foreach($submitters['Result']['submitters'] as $sub)
  {
      echo "Submitter ".$sub['Result']['submitter_id'];
      foreach($report_attrid as & $reportattrid1):

   $submitters['Result']['sub']=$this->Result->find('all',array('conditions'=>array('Result.attribute_id'=>$reportattrid1['Report']['attribute_id'],'Result.submitter_id'=>$sub['Result']['submitter_id'])));

          echo "values ".$submitters['Result']['sub'][0]['Result']['value'];

         endforeach;
  }



      $this->set('submitters',$submitters);

显示为

   Submitter 1 values NIsha values Below 5 Yrs
   Submitter 6 values Aruna values Above 10 yrs 

其中$ report_attrid用于检索通过操作发送的所选$ report_id的所有报告attribute_id ..

然后我使用$ submitters ['Result'] ['submitters']找到表单的提交者;

然后对于每个提交者,然后foreach attribute_id,我从$ report_attrid得到它我找到相应的属性ID的值,我得到了值   $提议者[ '结果'] [ '子'];

控制器端的一切正常..

但我不知道如何使用所有这些在视图中显示相同的内容

我已尝试过

   
                                <?php echo "submitter id ".$sub['Result']['submitter_id'];?>  
  <?php endforeach; ?>

显示提交者ID 1提交者id = 6

请帮助我在视图中获取值..

1 个答案:

答案 0 :(得分:6)

如果你在控制器中写道:

$this->set('anything', $a);

在视图中你应该使用:

<?php echo $anything;?>