2012-04-13 43 views
1

如何檢索使用Javascript在yii框架中動態填充數據的值?當我發佈它插入數據庫nullyii dropDownList使用Javascript發佈空值動態填充數據

鑑於

<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 
} 
+0

你在哪裏發佈數據到數據庫?你能提供那個代碼嗎? – squarephoenix 2012-04-13 19:09:45

+0

編輯了代碼。 – memo 2012-04-13 19:15:05

+0

查看這裏的第一個函數:http://www.yiiframework.com/doc/guide/1.1/en/form.table,你可能必須使用getItemsToUpdate();然後循環$模型來分配屬性1,一次修復 – squarephoenix 2012-04-13 19:47:57

回答

0

你有沒有加入 'otherdate', 'othermonth' 和 'otheryear' 的規則你的模型?

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

作品令人驚歎,感謝你。 – memo 2012-04-13 19:47:33