我认为我的cakephp项目中的分页有点太晚了,所以现在我有现有的(复杂的)HABTM查找操作(带有动态顺序,标签搜索等等)。是否可以在此时进行cakephp分页?或者我自己更好/更容易地进行分页(从ID xx中找到接下来的20个条目......)? 我已经搜索了很长时间寻找解决方案但实际上我没有找到任何有用的信息
答案 0 :(得分:1)
无论你做什么,你做了多么复杂的应用程序,你只需要一些语法更改来制作分页,我也一样,请检查我实施的解决方案。
$conditionSearchLessonsByCourse = array('CourseLessonsReference.is_active'=>1,
'Course1.is_active'=>1 ,
'CourseCategory.is_active'=>1,
'Reference.is_active'=>1
);
//Pagination logic
$this->paginate = array('conditions' => $conditionSearchLessonsByCourse,
'order' =>'CourseLessonsReference.id DESC',
'limit' => PAGINATION_LIMIT,
"joins" => array(
array(//UserCourse = Course Join
"table" => "courses",
"alias" => "Course1",
"type" => "INNER",
"conditions" => array(
"Course1.id = CourseLessonsReference.course_id"
)
),//For Category = Course Join
array(
"table" => "course_categories",
"alias" => "CourseCategory",
"type" => "INNER",
"conditions" => array(
"CourseCategory.id = Course1.course_category_id"
)
)
),
'recursive' => 2
);
$allLessonReferences = $this->paginate('CourseLessonsReference');