我正在使用 cakephp 2.1 并开发一个应用程序,其中包含以下表结构。
1. people(id, name)
2. movies(id, name)
和“人物”habtm
电影的表格如下。
1. castsmovie(id, person_id, movie_id)
2. directorsmovie(id, person_id, movie_id)
3. moviesmusicdirector(id, person_id, movie_id)
4. moviesproducers(id, person_id, movie_id)
5. movieswriter(id, person_id, movie_id)
6. cinematographersmovie(id, person_id, movie_id)
我想为特定的人获取电影并为他分页电影。所以我写的代码在控制器中
$this->paginate = array('Person' => array(
'contain' => array(
'CastsMovie' => array('Movie'),
'DirectorsMovie' => array('Movie'),
'MoviesProducer' => array('Movie'),
'MoviesMusicDirector' => array('Movie')),
'MoviesWriter' => array('Movie'),
'CinematographersMovie' => array('Movie')
),
'conditions' => array('Person.id' => $id)));
结果如下
array(
(int) 0 => array(
'Person' => array(
'id' => '101',
'name' => 'Darshan Thoogudeep',
),
'CastsMovie' => array(
(int) 0 => array(
'id' => '53',
'movie_id' => '14',
'person_id' => '101',
'order' => '1',
'Movie' => array(
'id' => '14',
'name' => 'Krantiveera Sangolli Rayanna',
)
),
(int) 1 => array(
'id' => '78',
'movie_id' => '19',
'person_id' => '101',
'order' => '0',
'Movie' => array(
'id' => '19',
'name' => 'Saarathi',
)
),
(int) 2 => array(
'id' => '137',
'movie_id' => '35',
'person_id' => '101',
'order' => '1',
'Movie' => array(
'id' => '35',
'name' => 'BulBul',
)
),
(int) 3 => array(
'id' => '153',
'movie_id' => '42',
'person_id' => '101',
'order' => '0',
'Movie' => array(
'id' => '42',
'name' => 'Viraat',
)
)
),
'CinematographersMovie' => array(),
'DirectorsMovie' => array(),
'MoviesMusicDirector' => array(),
'MoviesWriter' => array(),
'MoviesProducer' => array()
)
)
但我想获取限制为 20 的特定人的所有电影。这样我就可以轻松地对每页中电影的限制进行分页。请帮我解决问题。工作更受赞赏。