can't generate dropdownlist with gii or yiic


I really like this Framework specially the crud code generator using yiic or gii , but the main problem for me is that all generated form is textboxes only,

for example:

I have two tables one for students and another for countries , when create a new student I want to select country from a dropdownlist.

I don’t know how to configure the yiic or gii to generate dropdownlist for country??.

do i have to rename the fields in database in special way? or what … I need your help please.

thank you in advance.

I’m pretty sure you have to do this manually.

You just need to use listData. For example, in you controller or view select all available options for dropdown list:

$countries = CHtml::listData(Country::model()->findAll(array('order'=>'name')), 'id', 'countryId');

where id is a primary key in Country table and countryId is a FK (Student table). Then in your view file:

<?php echo CHtml::activeLabelEx($model, "country"); ?>

<?php echo CHtml::activeDropDownList($model, "country", $countries); ?>

Something like this with little changes should work for you.

Thank you for your help, your code working fine with me, but I still hope the generator do every thing from the beginning , I think this is very important feature specially with large database.

There is gii templates that can do this for you (although i never tried)