Unable To Get Combo Box Value To Save?

I am new to YII. I have form which is used "Role" combo box (from model there is method). When I store in db , the value is always 0. The html is below


<div class="row">

	<?php echo $form->labelEx($model,'userType'); ?>

        <?php echo $form->dropDownList($model,'userType', $model->getUserTypeOptions()); ?>        

	</div>

and then my model is


public function getUserTypeOptions()

        {

           return array(

               '1' => 'Administrator',

               '2' => 'Team Member'

           ); 

        }

             

How to resolve this problem?

Have you included ‘userType’ attribute in model’s rules?




public function rules()

{

    return array(

       array('userType', 'required'), // or 

       array('userType', 'safe'),  // (depend on your needs)

    );

}



It worked out, thanks @rei … awesome!!!