Ravi Bhalodiya, on 06 November 2012 - 04:29 AM, said:
I am new in Yii. I have two tables. info and gender.
info table contain three fields : id, name, gender_id.
gender table contain two fields : id, name('Male','Female')
gender_id is foreign key of gender table.
Now my question is, can gii generate dropDown for the field gender_id of info table when i generate crud for info table?

Yes. You mast override the method "generateInputField" from CrudCode class
Here my example
public function generateInputField($modelClass, $column) {
$relationModel = FALSE;
if($column->isForeignKey) {
$relationModel = $this->getRelationClassname($modelClass, $column->name);
}
$dbType = $column->dbType;
preg_match('/([a-z]+)/i',$column->dbType, $matches);
if(count($matches) > 0) {
$dbType = $matches[0];
}
if(($size=$maxLength=$column->size)>60)
$size=60;
switch ($dbType) {
case 'tinyint':
return "CHtml::activeDropDownList(\$model, '{$column->name}', array())";
break;
case 'int':
if($relationModel !== FALSE) {
return "CHtml::activeDropDownList(\$model, '{$column->name}', CHtml::listData({$relationModel}::model()->findAll(), '', ''))";
} else {
return "CHtml::activeTextField(\$model,'{$column->name}',array('size'=>$size, 'maxlength'=>$maxLength, 'class'=> 'text small'))";
}
break;
case 'text':
return "CHtml::activeTextArea(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50))";
break;
case 'datetime':
return "Yii::app()->dateFormatter->formatDateTime(\$model->{$column->name})";
break;
case 'varchar':
default:
if(preg_match('/^(password|pass|passwd|passcode)$/i',$column->name))
$inputField='activePasswordField';
else
$inputField='activeTextField';
return "CHtml::{$inputField}(\$model,'{$column->name}',array('size'=>$size, 'maxlength'=>$maxLength, 'class'=> 'text medium'))";
}
}