set() data is not being passed to view
view/plans/index.ctp
<?php debug($plans); ?>
controllers/plans_controller.php (index function)
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));
Here is a sample index() debug record from the plans_controller.php (as you can see all data is being contained properly using containa开发者_如何学运维ble):
[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
)
)
)
The containable data is not being passed. Only data associated with Plan and PlanDetail (no deeper relations than PlanDetail such as Company or Plan type), but the debug in the index controller shows all data being passed! But none of this data is making it into the view debug???
Does anyone know if this is a bug with containable?
You must either paginate
or find
, you can't paginate the found data array. Pagination is retrieving data from the database. Replace your find
call with a paginate
call. Save the result of the paginate
call in a variable and debug
it, your problem is there, not in the set
call.
After 8 hours pain, I solved it : ) and I added pagination to boot. I ended up using compact() in place of the baked set().
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'));
}
精彩评论