In your $dataProvider add a condition where it only allows current user… i.e. if you are using the default gii created it should be your $model->search()
public function search($user_id)
{
$criteria=new CDbCriteria;
//used for lazy load...this would be your relation to reports
//$criteria->with = array('user');
//$criteria->together = true;
//user_id would be the relating column to your user table to show ownership of the report
$criteria->addCondition('user_id ='.$user_id);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
This will return only items for the current user. If you use this else where it won’t work without declaring a $user_id in the function ie. search($user_id). You could create two different search functions maybe a user_search($user_id) and search()
public function scopes()
{
return array(
'findUsersRaports'=>array(
'condition'=>"UserName='".Yii::app()->user->name."'",
'order'=>'Id DESC',
),
);
}
And in my controller
public function actionIndex() {
if(Yii::app()->user->role == "myRole") {
$dataProvider=new CActiveDataProvider(Raport::model()->findUsersRaports());
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
///rest of the code