Clistview Error - Trying To Get Property Of Non-Object

Hi

I am still fairly new to Yii and not too sure if I am using the correct way to pull & display the following query.

I have a few complex SQL queries to run based upon my users ID across several tables.

When I do a var_dump I can see my array with the correct records but I am struggling to output them to a list view

I have tried several methods with no results, the closet I have got is by using a CArrayDataProvider but I am getting a error ‘Trying to get property of non-object’

Any help or advice on the correct method would be most appreciated.

In My Controller view i have:




public function actionIndex()

	{

		$rawData= Yii::app()->db->createCommand('SELECT * FROM player LEFT JOIN player_venues ON player.id = player_venues.player_id WHERE player_venues.venue_id=:id')->bindValue('id',$id)->queryAll();

		

		// I can see 3 records been returned !

		// var_dump($rawData);

		

		$dataProvider=new CArrayDataProvider($rawData);

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

			'dataProvider'=>$dataProvider,

		));

	}



In my index.php i have:




<h1>Players</h1>


<?php $this->widget('zii.widgets.CListView', array(

        'dataProvider'=>$dataProvider,

        'itemView'=>'_view',

)); ?>



In my _view.php I have:




<div class="row view-list">

	<div class="small-7 mini-6 medium-6 large-6 column">

		<h2><?php echo CHtml::encode($data->player_salutation); ?> <?php echo CHtml::encode($data->player_forename); ?> <?php echo CHtml::encode($data->player_surname); ?></h2>

		<p><b><?php echo CHtml::encode($data->getAttributeLabel('player_membership_number')); ?>: </b><?php echo CHtml::encode($data->player_membership_number); ?></p>

		<p><b><?php echo CHtml::encode($data->getAttributeLabel('player_email_address')); ?>: </b><?php echo CHtml::encode($data->player_email_address); ?></p>

		<p><b><?php echo CHtml::encode($data->getAttributeLabel('player_telephone')); ?>: </b><?php echo CHtml::encode($data->player_telephone); ?></p>

		<p><b><?php echo CHtml::encode($data->getAttributeLabel('player_mobile')); ?>: </b><?php echo CHtml::encode($data->player_mobile); ?></p>

		<p><b><?php echo CHtml::encode($data->getAttributeLabel('player_city')); ?>: </b><?php echo CHtml::encode($data->player_city); ?></p>

		<p><b><?php echo CHtml::encode($data->getAttributeLabel('player_postcode')); ?>: </b><?php echo CHtml::encode($data->player_postcode); ?></p>

	</div>

</div>



Many thanks in advance

GPM

Hi,

Try this for values and comment the labels check for one values, If works try alternative for labels




<?php echo CHtml::encode($data['player_surname']); ?>



Hi

Many thanks for your help in solving my problem




<?php echo CHtml::encode($data['player_surname']); ?>



Worked great!

You mentioned an alternative for Labels?




<?php echo CHtml::encode($data->getAttributeLabel('player_telephone')); ?>



Once again, many thanks

GPM

Yes, you print the array structure of data provider and check for labels if not available then go for any other alternatives.

Like model->getAttributeLabels… and so on

Cheers !

If works don’t hesitate to press +

And once again I have to wonder why one would go through the hassle of feeding a CArrayDataProvider the resultset of a query instead of using a CSqlDataProvider directly :huh:

A full paste of the error would help, btw ::)