probably a very newbish question, but I’ve literally just started using Yii and frameworks in general and am a bit lost.
Basically let’s say I have Country table (id, name) and city table (id, country_id, name). I made city.country_id associate with country.id via FK comment thing.
Now, when I load up city view right now it shows:
Id - …
Country_id - …
Name - …
What I want is to change country_id into country.name
That is because you don’t have a relation named country in your model class. Either define a relation in relations method or change country to whatever is the name of your relation.
you always have a public function that contains all the relations
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'idCounty' => array(self::BELONGS_TO, 'name_of_your_model that you are going to use', 'id_country'),
);
}
-----in your index view ---------
note: i use yii booster but, the function is very similar
'data'=>$model,
'attributes'=>array(
array ('name'=>'id_contry',
'value'=>$model->idCounty->name of the column you need to display,
'type'=>'text',
),
),