And I do have a field called country (generated by yii-user profile fields)
And I also have a database Country.
My question is. How can I access the country_id through the "profileController"
For example. in my profile page, we can see
Username:admin
Country: U.S.A
I want to add a button like "click to login to your country"
So I need to access that user’s country id here.
What should I do?
I tried this: but give me a syntax error:
private $_country = null;
public function getCountry()
{
$user=Yii::app()->user->id;
$_country= Yii::app()->db->createCommand('select country_id FROM tbl_profiles WHERE user_id=$user')->queryAll();
return $this->_country;
}
I guess I can’t use $user in SQL query…
What should i do to access the user’s country id anyway???
These information is stored in my database “tbl_profiles” But i don’t know how to access them…So sad…
a bit confusing about your loadCountry function, or maybe i miss some points (still new to yii)
how about this?
public function getCountry()
{
if ($this->_country === null) {
$this->_country=Profile::model()->findByAttributes(array('user_id'=>Yii::app()->user->id));
}
return $this->_country;
}