Just learning yii and creating a simple application… ran into a problem with activedropdown.
I have 2 tables…
User
====
-
user_id (integer, primary key)
-
user_name (varchar)
-
user_country (integer)
Country
=======
-
country_id (integer, primary key)
-
country_name (varchar)
in the country model, i’m have a function that gets all country names from the database with their ids.
public function getCountryList()
{
$criteria=new CDbCriteria;
$criteria->select=country_id,country_name';
$qCountries=Country::model()->findAll($criteria);
}
in the _form.php belonging to user view, i have the following code, but the drop down box does not even appear. I have a blank space there…
<?php CHtml::activeDropDownList($model, 'user_country', CHtml::listData($model,'country_id','country_name')); ?>
User model contains the following relation…
'usr_country'=>array(self::HAS_ONE, 'Country', 'country_id'),
Database type is InnoDB. There’s no foreign key in the user table that links user_country field to country_id field in Country table.
Could someone please point me to my mistake?