List only for logged in user CActiveDataProvider

I have a "User" class and a "Application" class.

There is a MANY_MANY relation between the 2.

In the ApplicationControl indexAction, I want to list only the Applications that the user has access to, instead of all the Applications (like it does by default).

What’s the Yii way of doing this?

I’m trying to avoid looping over and all…

I see that the default action uses CActiveDataProvider. I assume I could write complex SQL criteria for joins and all, but I’m hoping Yii can auto-generate that stuff for something basic like this.

why many_many? one user has more applications or no? HAS_MANY? If the relation is correct then u can get applications in your user model.

$x = new User();

x->applications; // the name of your relation

yes many_many. An application can have many users, and a user can have many applications.

But the "index" action uses CActiveDataProvider, so I believe the preferred way is to use this class?

I think I got it:


	 * Lists all models.


	public function actionIndex()


		$user = User::model()->findByPk(Yii::app()->user->id); 

                $dataProvider=new CActiveDataProvider('Application');