【问题标题】:yii dropDownList populated data dynamically with Javascript posting null valuesyii dropDownList 使用 Javascript 发布空值动态填充数据
【发布时间】:2012-04-13 19:05:31
【问题描述】:

如何在yii 框架中检索使用 Javascript 动态填充数据的值?当我发布数据时,它会将数据库插入为null

在视图中

<ul class="birthday">
    <li><?php echo $form->dropDownList($model, 'otherdate',array());?></li>
    <li><?php echo $form->dropDownList($model, 'othermonth',array());?></li>
    <li><?php echo $form->dropDownList($model, 'otheryear',array());?></li>
<script type="text/javascript">
    date_populate("EmailForm_otherdate", "EmailForm_othermonth", "EmailForm_otheryear");
</script>
</ul>

在控制器中

$model = new EmailForm;
if (isset($_POST['EmailForm'])) {
$model->attributes = $_POST['EmailForm'];
echo $model->otherdate; //value null
}

【问题讨论】:

  • 您在哪里将数据发布到数据库?你能提供那个代码吗?
  • 在这里查看第一个函数:yiiframework.com/doc/guide/1.1/en/form.table,您可能必须使用 getItemsToUpdate();然后循环 $model 以一次分配属性 1

标签: php javascript jquery forms yii


【解决方案1】:

您是否在模型的规则中添加了“otherdate”、“othermonth”和“otheryear”?

public function rules() 
{
    return array(
        array('otherdate, othermonth, otheryear', 'safe'),
    );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多