Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to count $dataProvider items

Tags:

how can i count data that will retrieved by $dataProvider ? i've tried to use this code,

       $dataProvider = new CActiveDataProvider('Model');
       $dataProvider->totalItemCount;
like image 905
if412010 Avatar asked Jan 20 '14 04:01

if412010


2 Answers

In yii2

For total count use

$dataProvider->getTotalCount()

For page count then

$dataProvider->getCount()

Refrence page http://www.yiiframework.com/doc-2.0/yii-data-basedataprovider.html#getTotalCount()-detail

like image 104
ishtiaq ahmed Avatar answered Oct 16 '22 05:10

ishtiaq ahmed


I think you have to first fill the dataprovider with data then get the count:

 $dataProvider->getData();
 var_dump($dataProvider->totalItemCount);

or use the function to retrieve directly:

 var_dump($dataProvider->getTotalItemCount());
like image 38
Developerium Avatar answered Oct 16 '22 06:10

Developerium