Wednesday, February 22, 2012

Make dropdownlist in yii framework

Oke let's take a look how to make a yii dropdownlist box. In yii you can easily build your dropdown list box using CHtml::dropdownListbox

Suppose you have a table of tbl_country

country_name | id
Indonesia        | 1
USA               | 2

And you want to add your data into a form in your model to show as a dropdown list. Just edit your _form files in your view and add this following code


       <div class="row">
  <?php echo $form->dropDownList($model,'country_id',
   CHtml::listData(Country::model()->findAll(), 'id', 'country_name'),
   array('empty'=>'Select Country'))?>
 </div>
That's just simple to do with yii. Have to try it!..

2 comments:

  1. Hi but while updating the drop down value is not selected as per the insertion. It displays all the values but not selected value.

    ReplyDelete