Paginate from within a model in CakePHP

前端 未结 4 796
情深已故
情深已故 2020-12-01 11:25

I have a function in my Event model called getEvents - you can pass limit, start and end dates, fields,

4条回答
  •  感情败类
    2020-12-01 12:02

    $paginate array are similar to the parameters of the Model->find('all') method, that is: conditions, fields, order, limit, page, contain, joins, and recursive.

    So you can define your conditions like this :

    var $paginate = array(
     'Event' => array (...)
     );
    

    Or you can also set conditions and other keys in the $paginate array inside your action.

     $this->paginate = array(
     'conditions' => array(' ... '),
     'limit' => 10
     );
     $data = $this->paginate('Event');
    
    • http://book.cakephp.org/2.0/en/controllers.html
    • http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html

    R u using $name = 'Event' in your controller ?

    If we wont mention model name in $this->paginate() , it will use model as mentioned in $name otherwise look in var $uses array and in that will get Model name (first one )

    for e.g var $uses = array('Model1','Model2'); // $name != mentioned

    n you want pagination with respect to Model2 then you have to specify ModelName in paginate array like $this->paginate('Model2') otherwise Model1 will be considered in pagination.

提交回复
热议问题