Hi, to all any help will be appreciated. I have the actionAdmin in my controller and CGridView as follows.

I need to show only the listings for the current logged in user and not show the listings that belongs to the other user. I give all the rights view, update and delete in the ‘CButtonColumn’. Just want to show the record for the user that is logged in if he/she created an listing and display Not found if no record found. I have a link Manage Listings that should be clicked before showing this CgridView. I tried the following in the actionAdmin but does not work.


	 * Manages all models.


	public function actionAdmin()


		$model = new Listings('search');

                if($model->author_id == Yii::app()->user->id){

		$model->unsetAttributes();  // clear any default values








And my CGridView I have

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



//'filter' => $model->author_id == Yii::app()->user->id,



     'name' => 'year',

     'type' => 'raw',

     'value' => 'CHtml::link(CHtml::encode($data->year), $data->url)'



     'name' => 'make',

     'type' => 'raw',

     'value' => 'CHtml::link(CHtml::encode($data->make->make), $data->url)'



        'name' => 'status',

        'value' => 'AutoLookup::item("PostStatus", $data->status)',

        'filter' => AutoLookup::items('ListStatus'),






)); ?>

I got it working the way i need by placing this peace of code in the method search in the model

$criteria->compare('author_id', Yii::app()->user->id, $partialMatch = false);

This will give me all the posts or whatever that has been posted by the current logged in in a CGridView

This is just what I was looking for. Thanks for sharing.

You can also use defaultScope to force the find() methods to add a WHERE clause automatically.