How to Limit the paginate in cakephp

前端 未结 5 1496
时光说笑
时光说笑 2021-01-17 23:58

How to Limit the paginate in cakephp ?

Assume that i have 400 records.
I need to get only 25 records from 50th record to 75th record and need to display 5 recor

5条回答
  •  梦谈多话
    2021-01-18 00:11

    Improved version with reference of: http://www.mainelydesign.com/blog/view/best-paginatecount-cakephp-with-group-by-support

    This return the correct total count base on whichever is less.

    public function paginateCount($conditions = null, $recursive = 0, $extra = array()) 
        {
            $conditions = compact('conditions');
            if ($recursive != $this->recursive) {
                $conditions['recursive'] = $recursive;
            }
            unset( $extra['contain'] );
            $count = $this->find('count', array_merge($conditions, $extra));
    
            if (isset($extra['group'])) {
                $count = $this->getAffectedRows();
            }
    
            if (isset($extra['totallimit']) && $extra['totallimit'] < $count) {
                return $extra['totallimit'];
            }
    
            return $count;
        }
    

提交回复
热议问题