查看/计划/ index.ctp
<?php debug($plans); ?>
controllers / 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()调试记录(正如您可以看到使用可包含的所有数据正确包含):
[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 :(得分:2)
您必须paginate
或 find
,您无法对找到的数据数组进行分页。分页 从数据库中检索数据。通过find
来电替换您的paginate
来电。将paginate
调用的结果保存在变量debug
中,您的问题就在那里,而不是在set
调用中。
答案 1 :(得分: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'));
}