0

I have following code in my view

<?php echo $form->dropDownList($model,'p_28',
    CHtml::listData(AdCourt::model()->findAll(),'id','name') ,
    array(
        'class'=>'form-control',
        'style'=>'width:100%;',

        'empty'=>Yii::t('plaint','Суд турини танланг'),
        'ajax' => array(
            'type'=>'POST', //request type
            'url'=>$this->createUrl('getcourts'),
            'update'=>'#ABlockForm_p_29',
        )
    )); ?>

AdCourt takes values from ad_court table. This tables consists of id, name and court_id. I need to save database court_id instead of id.

How can I do it?

topher
  • 14,790
  • 7
  • 54
  • 70
phpdev
  • 511
  • 4
  • 22

1 Answers1

1

The second parameter of listData is the attribute of the items that will be used as the value for the <option> tag. As such to use the court_id instead of the id you should pass it instead:

CHtml::listData(AdCourt::model()->findAll(),'court_id','name')
topher
  • 14,790
  • 7
  • 54
  • 70