Find Out Dataprovider In Index Page Is Empty Or Not

hi all , im using yii for about 3month,

I created a crud from a model.

in index action , I use $dataprovider = CActiveDataProvider…

but i dont want to use CListView.

anyway , I want to check if $dataProvider is empty or not,

but I have problem, ’ if($dataprovider) ’ allways returns true, even the query result is empty.

can anyone help me please ?

Hi,

can you post the code on $dataprovider?

yes , here it is :

    $dataProvider = new CActiveDataProvider('Data', array('criteria' => array(


            'condition' => $cond,


            'order' => 'id DESC',


        ),


        'pagination' => array('pageSize' => 8 )


    ));


    $this->render('index', array(


        'dataProvider' => $dataProvider,


    ));

sorry i am not getting the issue

can you post the all controller code?

$dataProvider = new CActiveDataProvider(‘Data’, array(‘criteria’ => array(

‘condition’ => $cond,

‘order’ => ‘id DESC’,

),

‘pagination’ => array(‘pageSize’ => 8 )

));

$this->render(‘index’, array(

‘dataProvider’ => $dataProvider,

));

view/data/index.php :

if($dataProvider) { // always returns true

/**

*/

}

Hi Alireza,

CActiveDataProvider is not an array of data, but it’s a “provider” of it. Once you have created it, it can never be null because it’s an object.

You can tell if the query result is empty or not by checking "totalItemCount" property of it.

http://www.yiiframework.com/doc/api/1.1/CDataProvider#totalItemCount-detail

I would like to recommend you to read through this wiki:

http://www.yiiframework.com/wiki/381/cgridview-clistview-and-cactivedataprovider

thank you wery much,