在cakephp中加入join和array

时间:2015-02-22 12:42:20

标签: cakephp pagination

在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');

1 个答案:

答案 0 :(得分:0)

如果将选项拆分为自己的变量

,则分页有效