anyabythestars
anyabythestars

Reputation: 157

How to input condition in yii find()?

I have two tables Account and User.

Account table contains account_id, username, password

while User table contains user_id, account_id, first_name, last_name.

What I want is for yii to display the contents of the user table of the one logged in so I used this code

$user= Yii::app()->user->id; //to get the account_id of user logged in
$userModel = User::model()->find(array('condition'=>'account_id' == $user));
//to find data in the user table with the account_id similar to the
//account_id of the one logged in
print_r($userModel); //to check if I got the correct data

but for some reason, no matter who logs in, the print_r($userModel) is returning data with the account_id == 1

please help :/

Upvotes: 2

Views: 71

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

If you are using Yii 1 you can try with findByAttribute

$userModel = User::model()->findByAttributes(array('account_id'=>$user));

Upvotes: 1

Related Questions