CListView and CSqlDataProvider

I’m trying to get a paginated list view.

In my controller I have this





$listsql = 'SELECT * FROM unitlistings where '.$whereClause;

$dataProvider=new CSqlDataProvider($listsql, array(

			'totalItemCount'=>$resultCount,

			'keyField'=>'refno',

			'pagination'=>array(

				'pageSize'=>10,

			 ),

		));

				

		$this->render('search', array('dataProvider'=>$dataProvider,

In my view file search.php I have this


<?php 

					$this->widget('zii.widgets.CListView',

						  array(

							  'dataProvider'=>$dataProvider,

						      'itemView'=>'searchlist',

							  'id'=>'postListView',

							  'enablePagination'=>true,

							  'enableSorting'=>false,

							)); ?>

In searchlist file I’m getting error Trying to get property of non-object


<?php echo $data->category ; ?>

where category is the name of a field in the table unitlistings

When I used <?php foreach($data as $list) echo $list[‘category’]; echo $list[‘property’]; etc… I was getting output 2 everywhere I used $list->

Pagination is working fine. Getting correct number of results and items per page.

Try


$data["category"]

instead.

Thanks. That solved the problem

You can always vote my post up ::)