Adrianna
(Rhea Uplb)
June 16, 2014, 6:05am
1
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.
Example.
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.
ahmed201
(Rifajas)
June 16, 2014, 6:25am
2
adrianna:
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.
Example.
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?
Adrianna
(Rhea Uplb)
June 16, 2014, 6:30am
3
Yes Ahamed. One user may be classified into many classification.
ahmed201
(Rifajas)
June 16, 2014, 6:41am
4
adrianna:
Yes Ahamed!
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.
so
$user->classifications
return array of classification objects so you can iterate it to display of do something whatever you want.
Adrianna
(Rhea Uplb)
June 16, 2014, 7:00am
5
Ok. I will try to implement that on my application. Thank you Ahamed!