yii\data\BaseDataProvider::setPagination PHP Method

setPagination() public method

Sets the pagination for this data provider.
public setPagination ( array | Pagination | boolean $value )
$value array | Pagination | boolean the pagination to be used by this data provider. This can be one of the following: - a configuration array for creating the pagination object. The "class" element defaults to 'yii\data\Pagination' - an instance of [[Pagination]] or its subclass - false, if pagination needs to be disabled.
    public function setPagination($value)
    {
        if (is_array($value)) {
            $config = ['class' => Pagination::className()];
            if ($this->id !== null) {
                $config['pageParam'] = $this->id . '-page';
                $config['pageSizeParam'] = $this->id . '-per-page';
            }
            $this->_pagination = Yii::createObject(array_merge($config, $value));
        } elseif ($value instanceof Pagination || $value === false) {
            $this->_pagination = $value;
        } else {
            throw new InvalidParamException('Only Pagination instance, configuration array or false is allowed.');
        }
    }

Usage Example

 /**
  * Constructor.
  * @param BaseDataProvider $dataProvider the data provider to iterate over
  * @param integer $pageSize pageSize to use for iteration. This is the number of objects loaded into memory at the same time.
  */
 public function __construct(BaseDataProvider $dataProvider, $pageSize = null)
 {
     $this->_dataProvider = $dataProvider;
     $this->_totalItemCount = $dataProvider->getTotalCount();
     if (($pagination = $this->_dataProvider->getPagination()) === false) {
         $this->_dataProvider->setPagination($pagination = new Pagination());
     }
     if ($pageSize !== null) {
         $pagination->pageSize = $pageSize;
     }
 }
All Usage Examples Of yii\data\BaseDataProvider::setPagination