douzong3599 2014-09-09 10:22
浏览 151
已采纳

如何在更新函数中获取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();
                        if(!empty($images)){
                            $data = array();
                            $x = 1;
                            foreach ($images as $i){

                                array_push($data, $x);
                                $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 http://www.yiiframework.com/wiki/48/by-example-chtml/#hh5 ,

        <?php echo $form->labelEx($model,'order_id'); ?>
        <?php echo $form->dropDownList($model,'order_id',
         CHtml::listData(Homepage::model()->findAll(),'order_id','order_id'),
         array('empty'=>'--Select order --') ); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛