Fixes #16891: Fixed Pagination::totalCount initialized incorrectly

This commit is contained in:
taobig
2019-01-02 02:24:14 +08:00
committed by Alexander Makarov
parent 379a2002dd
commit e1623868f9
4 changed files with 55 additions and 5 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.16 under development
------------------------
- Bug #16891: Fixed Pagination::totalCount initialized incorrectly (taobig)
- Bug #16028: Fix serialization of complex cache keys that contain non-UTF sequences (rugabarbo)
- Bug #16945: Fixed RBAC DbManager ruleName fetching on the case of PDO::ATTR_ORACLE_NULLS => PDO::NULL_TO_STRING (razonyang)
- Bug #16081: Fixed composite IN using just one column (rugabarbo)

View File

@ -46,6 +46,9 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa
public $id;
private $_sort;
/**
* @var Pagination|false $_pagination
*/
private $_pagination;
private $_keys;
private $_models;
@ -183,8 +186,6 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa
/**
* Returns the pagination object used by this data provider.
* Note that you should call [[prepare()]] or [[getModels()]] first to get correct values
* of [[Pagination::totalCount]] and [[Pagination::pageCount]].
* @return Pagination|false the pagination object. If this is false, it means the pagination is disabled.
*/
public function getPagination()
@ -193,6 +194,13 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa
$this->setPagination([]);
}
if (($this->_pagination !== false) && ($this->_pagination->totalCount === null)) {
if ($this->_totalCount === null) {
$this->setTotalCount($this->prepareTotalCount());
}
$this->_pagination->totalCount = $this->_totalCount;
}
return $this->_pagination;
}

View File

@ -124,9 +124,9 @@ class Pagination extends BaseObject implements Linkable
*/
public $validatePage = true;
/**
* @var int total number of items.
* @var int|null total number of items.
*/
public $totalCount = 0;
public $totalCount;
/**
* @var int the default page size. This property will be returned by [[pageSize]] when page size
* cannot be determined by [[pageSizeParam]] from [[params]].