Cakephp 多数据块分页器查询结果
在蛋糕中使用Paginate后,我得到以下结果:Cakephp 多数据块分页器查询结果,cakephp,pagination,cakephp-2.4,paginator,Cakephp,Pagination,Cakephp 2.4,Paginator,在蛋糕中使用Paginate后,我得到以下结果: array( (int) 0 => array( 'DestinationPhoto' => array( 'id' => '1', 'name' => 'picture.jpg', 'destination_id' => '2' ),
array(
(int) 0 => array(
'DestinationPhoto' => array(
'id' => '1',
'name' => 'picture.jpg',
'destination_id' => '2'
),
'Destinations' => array(
'id' => '2',
'country_id' => '2'
),
'DestinationIdiom' => array(
'id' => '3',
'name' => 'TestName-1',
'description' => 'TestDescription',
'idiom' => 'English',
'destination_id' => '2'
)
),
(int) 1 => array(
'DestinationPhoto' => array(
'id' => '1',
'name' => 'picture.jpg',
'destination_id' => '2'
),
'Destinations' => array(
'id' => '2',
'country_id' => '2'
),
'DestinationIdiom' => array(
'id' => '4',
'name' => 'TestName-2',
'description' => 'TestDescription-2',
'idiom' => 'Spanish',
'destination_id' => '2'
)
)
)
似乎我在同一个结果中得到了由不同“DestinationDiom”引起的多个“DestinationPhoto”、“Destinations”实例,是否可以将这两个“DestinationDiom”合并显示为paginator的相同结果?像
array(
(int) 0 => array(
'DestinationPhoto' => array(
'id' => '1',
'name' => 'huehuehuehuh.jpg',
'destination_id' => '2'
),
'Destinations' => array(
'id' => '2',
'country_id' => '2'
),
'DestinationIdiom' => array(
(int) 0 => array(
'id' => '3',
'name' => 'TestName-1',
'description' => 'TestDescription',
'idiom' => 'English',
'destination_id' => '2'
)
(int) 1 => array(
'id' => '3',
'name' => 'TestName-2',
'description' => 'TestDescription',
'idiom' => 'Spanish',
'destination_id' => '2'
)
)
)
)
在DestinationPhoto控制器中,我有以下内容:
$this->paginate = array(
'fields'=>array('DestinationPhoto.*','Destinations.*','DestinationIdiom.*'),
'joins' => array(
array(
'table' => 'destinations',
'alias'=>'Destinations',
'type' => 'LEFT',
'conditions' => '`DestinationPhoto`.`destination_id` = `Destinations`.`id`'
),
array(
'table' => 'destination_idioms',
'alias'=>'DestinationIdiom',
'type' => 'LEFT',
'conditions' => '`DestinationIdiom`.`destination_id` = `Destinations`.`id`'
)
),
'limit' => 20
);
使用模型命名约定。将其设置为
目的地
,而不是目的地
在运行时绑定模型关联,如下所示:
$this->paginate = array(
'joins' => array(
array(
'table' => 'destinations',
'alias'=>'Destination',
'type' => 'LEFT',
'conditions' => '`DestinationPhoto`.`destination_id` = `Destinations`.`id`'
)),
'limit' => 20,
'recursive' => '2'
);
$this->DestinationPhoto->Destination->bindModel(array('hasMany' => array('DestinationIdiom' => array('className' => 'DestinationIdiom',
'foreignKey' => 'destination_id'))), false);
$result = $this->paginate('Destination');
pr($result);
die;