yii\data\Pagination::getOffset PHP Method

getOffset() public method

public getOffset ( ) : integer
return integer the offset of the data. This may be used to set the OFFSET value for a SQL statement for fetching the current page of data.
    public function getOffset()
    {
        $pageSize = $this->getPageSize();
        return $pageSize < 1 ? 0 : $this->getPage() * $pageSize;
    }

Usage Example

示例#1
0
 public function getListByCategory($slug, $fields = [], $with = [], $page = false, $pageSize = false, $order = '')
 {
     $category = Category::getInstance()->getBySlug($slug);
     $model = self::$model->find()->select($fields)->where(['type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE, 'meta_id' => $category['id']])->join('RIGHT JOIN', Relationship::tableName() . ' relation', 'content_id=id');
     $countModel = clone $model;
     $pagination = new Pagination(['totalCount' => $countModel->count(), 'pageSize' => $pageSize]);
     if ($page) {
         $pagination->setPage($page, true);
     }
     switch (strtoupper($order)) {
         case 'VIEW':
             $model->orderBy('view_total DESC');
             break;
         case 'COMMENT':
             $model->orderBy('comment_total DESC');
             break;
         case 'CREATED':
             $model->orderBy('created_at DESC');
             break;
         case 'UPDATED':
             $model->orderBy('updated_at DESC');
             break;
     }
     return ['data' => $model->with($with)->limit($pagination->getLimit())->offset($pagination->getOffset())->all(), 'pagination' => $pagination];
 }
All Usage Examples Of yii\data\Pagination::getOffset