2011-02-14 74 views
0

视图/计划/ index.ctp组()的数据没有被传递给查看

<?php debug($plans); ?> 

控制器/ plans_controller.php(指数函数)

function index() { 
    $plansC = $this->Plan->find('all', 
     array('contain' => array('PlanDetail' => array('fields' => array('id', 
     'effective_date', 
     'expiration_date', 
     'active', 
     'name', 
     'plan_type_id', 
     'max_benefit', 
     'deductible', 
     'preventive', 
     'basic', 
     'major', 
     'ortho', 
     'company_id', 
     'plan_type_id', 
     'plan_detail_note_id'), 
     'Company' => array('fields' => array(
      'id', 
      'company_logo_url' 
     )), 
     'PlanType' => array('fields' => array(
      'id', 
      'name' 
     )) 
    )))); 

    debug($plansC); 
    $this->set('plans',$this->paginate($planC)); 

这里是一个来自plans_controller.php的样本索引()调试记录(因为您可以看到所有数据正在使用可容纳的内容进行正确包含):

[0] => Array 
    (
     [Plan] => Array 
      (
       [id] => 7 
       [created] => 2011-01-10 14:11:40 
       [modified] => 2011-02-03 18:35:29 
       [plan_detail_id] => 32 
       [monthly_cost] => 25.49 
       [dental_cost] => 0.00 
       [age_id] => 2 
       [applicant_id] => 1 
       [state_id] => 1 
      ) 

     [PlanDetail] => Array 
      (
       [id] => 32 
       [effective_date] => 2011-01-10 14:07:00 
       [expiration_date] => 2011-01-10 14:07:00 
       [active] => 1 
       [name] => Classic 1500 
       [plan_type_id] => 2 
       [max_benefit] => 0.00 
       [deductible] => $75/year 
       [preventive] => 90% 
       [basic] => 75% 
       [major] => 50% 
       [ortho] => 
N/A 


       [company_id] => 4 
       [plan_detail_note_id] => 9 
       [Company] => Array 
        (
         [id] => 4 
         [company_logo_url] => nationwide_logo.png 
        ) 

       [PlanType] => Array 
        (
         [id] => 2 
         [name] => Indemnity 
        ) 

      ) 

    ) 

包含的数据未被传递。只有与Plan和PlanDetail相关的数据(没有比PlanDetail更深的关系,比如公司或计划类型),但是索引控制器中的调试显示所有正在传递的数据!但这些数据都没有进入视图调试?

有谁知道这是否是一个可容错的错误?

回答

0

经过8个小时的痛苦,我解决了它:),我加了分页启动。我最终使用compact()代替烘焙集合()。

function index() { 
    //$this->Plan->find('all'); not needed 
    $this->paginate['Plan'] = array('contain' => array('PlanDetail' => array('fields' => array('id', 
     'effective_date', 
     'expiration_date', 
     'active', 
     'name', 
     'plan_type_id', 
     'max_benefit', 
     'deductible', 
     'preventive', 
     'basic', 
     'major', 
     'ortho', 
     'application_url', 
     'company_id', 
     'plan_type_id', 
     'plan_detail_note_id'), 
     'Company' => array('fields' => array(
      'id', 
      'company_logo_url' 
     )), 
     'PlanType' => array('fields' => array(
      'id', 
      'name' 
     )) 
    ))); 
    $plans = $this->paginate('Plan'); 
    $this->set(compact('plans')); 
} 
2

您必须要么paginate要么find,你不能分页找到的数据数组。分页从数据库中检索数据。将您的find呼叫替换为paginate呼叫。将paginate调用的结果保存在一个变量中,并且debug它,您的问题在那里,而不是在set调用中。

+0

deceze,谢谢你的见解。我刚才用下面的代码解决了它。我认为这可能与寻找呼叫是多余的,但它现在完美地与分页工作。 – OldWest 2011-02-15 02:11:50

+0

我从我的下面的代码中删除了查找,并且我明确地看到您在paginator调用模型上的含义就像查找。 – OldWest 2011-02-15 02:16:08