Cant Gii Generate Dropdown In Place Of Textfield?

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????

Gii doesn’t do it (yet?), but there are several extensions that do it for you, although it’s quite easy to code manually if a handful of dropdowns are needed. The one I personally use is giix

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];






		switch ($dbType) {

			case 'tinyint':

				return "CHtml::activeDropDownList(\$model, '{$column->name}', array())";


			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'))";



			case 'text':

				return "CHtml::activeTextArea(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50))";


			case 'datetime':

				return "Yii::app()->dateFormatter->formatDateTime(\$model->{$column->name})";


			case 'varchar':






				return "CHtml::{$inputField}(\$model,'{$column->name}',array('size'=>$size, 'maxlength'=>$maxLength, 'class'=> 'text medium'))";



I tried it. But it throws following exception.

CrudCode and its behaviors do not have a method or closure named "getRelationClassname".

Sory, i override this class. And add new method getRelationClassname on it too.

	public function getRelationClassname($modelClass, $column) {

		$model = new $modelClass;

		$relations = $model->relations();

		foreach($relations as $relation) {

			if(isset($relation[2]) && $relation[2] == $column) {

				return $relation[1];



		return FALSE;


I tried this… But it still generates textFields. I dont know the problem. Is there any changes required in database side???