2011-02-14 11 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의 샘플 index() 디버그 레코드 (containable을 사용하여 모든 데이터가 올바르게 포함 된 것을 볼 수 있듯이) :

[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')); 
} 
+0

컴팩트는 해결책이 아니며 단지 편의를위한 것입니다. 문제 해결사는 $ this-> paginate()와 변수 $ this-> paginate입니다. –

+0

뭔가 잘못하고 있었음에 틀림 없지만 set()은 뷰에 데이터를 전달하지 않고 compact() 스위치를 사용하여 필요에 따라 작동하게했습니다. 그래서 무엇이 잘못되었는지는 모르지만 지금은 작동하고 두통은 사라졌습니다.) – OldWest

2

paginate또는find 중 하나 여야합니다. 발견 된 데이터 배열의 페이지를 매길 수 없습니다. 페이지 번호 은 데이터베이스에서 데이터를 검색하는입니다. find 호출을 paginate 호출로 바꿉니다. 변수에 paginate 호출 결과를 저장하고 debug 호출하면 set 호출이 아니라 문제가 있습니다.

+0

deceze, 통찰력을 위해 감사합니다. 나는 잠시 전에 아래의 코드로 그것을 풀었다. find 호출과 중복 될 수 있다고 생각하지만 지금은 페이지 매김과 완벽하게 작동합니다. – OldWest

+0

아래의 코드에서 찾기를 제거 했으므로 모델에 대한 호출을 호출하는 것과 정확히 일치한다는 것을 알 수 있습니다. – OldWest