2014-09-09 10:22
浏览 148

如何在更新函数中获取Yii dropDownList的选定值?

I have a problem in updating my model values, one of the model attributes is a number that is selected from a dropDownList, here is my code:

<?php $images = Homepage::model()->findAll();
                            $data = array();
                            $x = 1;
                            foreach ($images as $i){

                                array_push($data, $x);
                <?php echo $form->labelEx($model,'order'); ?>
                <?php echo $form->dropDownList($model, 'order', $data, array(
                    'empty'=>'Select image order',
                    'id'=>'order')); ?>

this dropDownList is containing the number of records of model (table) in the db, the problem is in the update function, for example: on the creation of (image 1) I selected 1 as the order value, then when I go to the update, I got the pre-selected option is 2 (which is the last value of the listData) instead of 1, so what is the error here ?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • dtzjvj3915 2014-09-09 14:32

    Im not a Yii expert but i think you are doing it wrong, Im using this code below and it works fine im getting the id from the database and showing it in the dropDown list, try it maybe it helps or check ,

        <?php echo $form->labelEx($model,'order_id'); ?>
        <?php echo $form->dropDownList($model,'order_id',
         array('empty'=>'--Select order --') ); ?>
    解决 无用
    打赏 举报

相关推荐 更多相似问题