在 cakephp 中使用连接和数组进行分页
pagination with join and array in cakephp
在 cakephp 中,我使用了 'find all' 来做一个复合体,效果很好,如下所示。我的问题是我正在尝试将其转换为一组分页结果,但我不断收到偏移警告非法偏移类型 [CORE\Cake\Model\Model.php,第 2936 行。
我确信这个问题很简单,但是有没有办法用我用于搜索的 $option 数组来做到这一点。我没有在文档中看到带有为选项设置数组的分页结果的示例
http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html
$this->Lesson->recursive = -1;
$options['joins'] = array(
array('table' => 'lessons_students',
'alias' => 'LessonsStudent',
'type' => 'LEFT',
'conditions' => array(
'Lesson.id = LessonsStudent.lesson_id',
)
),
array('table' => 'students',
'alias' => 'Student',
'type' => 'LEFT',
'conditions' => array(
'LessonsStudent.student_id=Student.id',
)
),
array('table' => 'subjects',
'alias' => 'Subject',
'type' => 'LEFT',
'conditions' => array(
'Lesson.subject_id=Subject.id',
)
),
array(
'table' => 'tutors',
'alias' => 'Tutor',
'type' => 'LEFT',
'conditions' => array(
'Lesson.tutor_id = Tutor.id'
)
) ,
array('table' => 'tutoring_types',
'alias' => 'TutoringType',
'type' => 'LEFT',
'conditions' => array(
'Lesson.tutoring_type_id=TutoringType.id',
)
)
);
$options['fields'] = array('Student.last_name','Student.first_name','Student.id',
'Lesson.lesson_date', 'Lesson.start_time', 'Lesson.end_time', 'Lesson.id','Lesson.schedule_rec','Lesson.schedule_monthly','Lesson.schedule_yearly',
'Lesson.cancelled_by', 'Lesson.makeup_lesson', 'Lesson.tutoring_type_id', 'Lesson.forefit',
'LessonsStudent.*',
'Tutor.last_name', 'Tutor.first_name','Tutor.id',
'Subject.name','Subject.id',
'TutoringType.*');
$options['conditions'] = array('Lesson.lesson_inactive' => 0,'Lesson.makeup_lesson' => 0,'Lesson.forefit' => 0,
'Lesson.lesson_date >= ' => $startdate, 'Lesson.lesson_date <= ' => $enddate,
'AND' =>array(
array('OR' => array(
array('Student.first_name LIKE' => '%' . $searchFirstName . '%'),
array('Tutor.first_name LIKE' => '%' . $searchFirstName . '%'),
array('Student.guardian_first_name LIKE' => '%' . $searchFirstName . '%'),
),
array('OR' => array(
array('Student.last_name LIKE' => '%' . $searchLastName . '%'),
array('Tutor.last_name LIKE' => '%' . $searchLastName . '%'),
array('Student.guardian_last_name LIKE' => '%' . $searchLastName . '%'),
) ,
array('OR' => array(
array('Student.student_mobile LIKE' => '%' . $searchmobile . '%'),
array('Tutor.mobile LIKE' => '%' . $searchmobile . '%'),
array('Student.guardian_mobile LIKE' => '%' . $searchmobile . '%'),
)
))))
);
$options['order'] =array('Lesson.lesson_date','Lesson.start_time');
$options['limit'] =150;
$options['page'] =1;
// $lessons= $this->Lesson->find('all', $options );
$options['recursive'] =50;
$this->Paginator->settings = array($options);
$lessons= $this->Paginator->paginate('Lesson');
如果您将选项拆分到自己的变量中,分页就可以工作
在 cakephp 中,我使用了 'find all' 来做一个复合体,效果很好,如下所示。我的问题是我正在尝试将其转换为一组分页结果,但我不断收到偏移警告非法偏移类型 [CORE\Cake\Model\Model.php,第 2936 行。 我确信这个问题很简单,但是有没有办法用我用于搜索的 $option 数组来做到这一点。我没有在文档中看到带有为选项设置数组的分页结果的示例
http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html
$this->Lesson->recursive = -1;
$options['joins'] = array(
array('table' => 'lessons_students',
'alias' => 'LessonsStudent',
'type' => 'LEFT',
'conditions' => array(
'Lesson.id = LessonsStudent.lesson_id',
)
),
array('table' => 'students',
'alias' => 'Student',
'type' => 'LEFT',
'conditions' => array(
'LessonsStudent.student_id=Student.id',
)
),
array('table' => 'subjects',
'alias' => 'Subject',
'type' => 'LEFT',
'conditions' => array(
'Lesson.subject_id=Subject.id',
)
),
array(
'table' => 'tutors',
'alias' => 'Tutor',
'type' => 'LEFT',
'conditions' => array(
'Lesson.tutor_id = Tutor.id'
)
) ,
array('table' => 'tutoring_types',
'alias' => 'TutoringType',
'type' => 'LEFT',
'conditions' => array(
'Lesson.tutoring_type_id=TutoringType.id',
)
)
);
$options['fields'] = array('Student.last_name','Student.first_name','Student.id',
'Lesson.lesson_date', 'Lesson.start_time', 'Lesson.end_time', 'Lesson.id','Lesson.schedule_rec','Lesson.schedule_monthly','Lesson.schedule_yearly',
'Lesson.cancelled_by', 'Lesson.makeup_lesson', 'Lesson.tutoring_type_id', 'Lesson.forefit',
'LessonsStudent.*',
'Tutor.last_name', 'Tutor.first_name','Tutor.id',
'Subject.name','Subject.id',
'TutoringType.*');
$options['conditions'] = array('Lesson.lesson_inactive' => 0,'Lesson.makeup_lesson' => 0,'Lesson.forefit' => 0,
'Lesson.lesson_date >= ' => $startdate, 'Lesson.lesson_date <= ' => $enddate,
'AND' =>array(
array('OR' => array(
array('Student.first_name LIKE' => '%' . $searchFirstName . '%'),
array('Tutor.first_name LIKE' => '%' . $searchFirstName . '%'),
array('Student.guardian_first_name LIKE' => '%' . $searchFirstName . '%'),
),
array('OR' => array(
array('Student.last_name LIKE' => '%' . $searchLastName . '%'),
array('Tutor.last_name LIKE' => '%' . $searchLastName . '%'),
array('Student.guardian_last_name LIKE' => '%' . $searchLastName . '%'),
) ,
array('OR' => array(
array('Student.student_mobile LIKE' => '%' . $searchmobile . '%'),
array('Tutor.mobile LIKE' => '%' . $searchmobile . '%'),
array('Student.guardian_mobile LIKE' => '%' . $searchmobile . '%'),
)
))))
);
$options['order'] =array('Lesson.lesson_date','Lesson.start_time');
$options['limit'] =150;
$options['page'] =1;
// $lessons= $this->Lesson->find('all', $options );
$options['recursive'] =50;
$this->Paginator->settings = array($options);
$lessons= $this->Paginator->paginate('Lesson');
如果您将选项拆分到自己的变量中,分页就可以工作