widget CListView with Junctiun of tables


After trying all day long to make it work, I couldn’t do it so I am finally asking for help… I am trying to use the Widget CListView in order to display the messages received by a user. I just have to link 2 tables (Message.FromUserId = User.UserId) and i want to display the following fields :




In SiteController.php I have:

$dataProvider=new CActiveDataProvider(





                        'together' => true,

                        'condition'=>'t.ToUserId=' . Yii::app()->user->userId(),




In Message.php :

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



)); ?>

And in the view _view :


    <td><?php echo CHtml::encode($data->Username); ?></td>

    <td><?php echo CHtml::encode($data->Subject); ?></td>

    <td><?php echo CHtml::encode($data->DateSent); ?></td>


The error message i get is :

"Property "Message.Username" is not defined.

If i remove the line in the _view concerning the $data->Username , it works just fine, so i guess it might somehow be related to the LEFT JOIN… or that I missed something big as I just started with the framework… The error message is quite explicit but i really can’t get how to solve this problem so I would be very grateful if someone could help me with that.

Thank you in advance.

Still haven’t found what is the problem… any help would be great!


try something like this:

on the model:

public function relations()


		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(


			'relationName' => array(self::BELONGS_TO, 'relatedtable', 'foreignkey'),




on the controller:


with = array (

	'relationName' => array('column1', 'column2', 'column3'),



on the view:


<?php echo CHtml::encode($data->relationName->column1); ?>


Thanks for the help :)!