Help With The Use Of Cdbcriteria

Hi guys. I need help in using CDbCriteria with my application. What I want is to display only list of classification belonging to a certain user.

Example. This is list of classification:

‘Class 1’

‘Class 2’

‘Class 3’




and so on.

The user logged in, on his/her index I want to see only classification that belongs to the user who logged in.


User 1 has classification ‘class 1’ only.

User 2 has classification ‘class 1 and class 2’. And so on…

I know this sounds easy but I just can’t do it. Thank you for the help.

what is your relationship between user and classification. one to many?

Yes Ahamed. One user may be classified into many classification.

you can use directly without using any criteria like this in the user controller

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

$classifications = $user->classification;

I assumed that you defined your relationship with your classification model as classifications so I find the user by currently loggedin user’s id with classifications.



return array of classification objects so you can iterate it to display of do something whatever you want.

Ok. I will try to implement that on my application. Thank you Ahamed!

ok. ;)