How To Fetch Data In Dropdownlist From Two Different Tables

Hi All,

I am new to yii framework. I want to do the following thing.

I am trying to create a user registration form in which one has to fill his all data.

In that form, he has to also select city . I have created City as table in which all cities will be stored.

while in user table only city id will be stored. Now, in user form view i am trying to fetch data

from city table. How should i do it. I have city as model also.

I tried following things but could not solve.

<

echo $form->dropDownList($model,‘City’, CHtml::listData(City::model()->findAll(), ‘CITY_ID’,‘CITY_NAME’));

//above code says error User.city is not defined what does that mean

>

I tried different solution on this forum still i was not able to do this. so posting this question. Please

help guys… waiting for solution

Got the solution :)





$city_model = City::model()->findAll(array('order' => 'CITY_NAME')); 

 $list = CHtml::listData($city_model, 'CITY_ID', 'CITY_NAME');    

 echo $form->dropDownList($model, 'UCity_ID', $list);       




my current model was User. This code i have added in user form.