CakePHP maximum pagination prefix not working

I am using cakephp 2.x. I can not set the maximum limit of my entry.

Please check my code:

App::uses('AppController', 'Controller');
class BroadcastsController extends AppController {
   public $components = array('Paginator');

   public function broadcast(){           
         $this->Paginator->settings = array('limit' => 10,  'order' => array('Broadcast.no_of_user' => 'DESC'), 'group' => 'Broadcast.broadcaster_id');
         $popularRooms = $this->Paginator->paginate('Broadcast');
         pr($popularRooms); //fetch 200 records
         $this->set('popularRooms', $popularRooms);
   }
}

Above pr($popularRooms);I get 200 entries, but I need the first 50 entries and the page to show 10 entries. I used 'maxLimit'=>50, but this code was the same as 'limit'=>50. Please help me.

+4
source share
5 answers

In this case, you can use the "extras" array in the paginator setting

$this->Paginator->settings = array('limit' => 10, 'max_record'=>50, 'order' => array('Broadcast.no_of_user' => 'DESC'), 'group' => 'Broadcast.broadcaster_id');

in your model or AppModel overriding the paginateCount function

class Broadcast extends AppModel { 
function paginateCount($conditions, $recursive, $extra) {
    $param = array_merge(compact('conditions', 'recursive'), $extra);
    $count = $this->find('count', $param);
    if (!empty($extra['max_record']) && $count > $extra['max_records']) {
      $count = $extra['max_record'];
    }
    return $count;
  } 
}
+4
source

CakePHP , 100. ,

public $paginate = array(
    // other keys here.
    'maxLimit' => 10
);

maxLimit

 $this->Paginator->settings = array('limit' => 10,'maxLimit'=>50,'order' => array('Broadcast.no_of_user' => 'DESC'), 'group' => 'Broadcast.broadcaster_id');
+1
public function list_posts() {
    $settings = array(
       'limit' => 25, // here
       'order' => array(
          'Post.title' => 'asc'
        )
    );
    $this->Paginator->settings = $this->settings;
    // similar to findAll(), but fetches paged results
    $data = $this->Paginator->paginate('Posts');
    $this->set('data', $data);

}

0

, $this- > Paginator- > settings =.

public function list_posts() {
$settings = array(
   'limit' => 25, // here
   'order' => array(
      'Post.title' => 'asc'
    )
);
// similar to findAll(), but fetches paged results
$data = $this->Paginator->paginate('Posts');
$this->set('data', $data);
0
source

Set maxLimit first in the paginator settings to this limit:

$this->Paginator->settings = array(
 'maxLimit' => 50,  
 'limit' => 10,  
 'order' => array('Broadcast.no_of_user' => 'DESC'), 
 'group' => 'Broadcast.broadcaster_id'
);

Just installing one of them logically does not change anything.

0
source

All Articles