[英]data is saved twice to the database
這是我的代碼:
public function actionPostTest()
{
if(isset($_POST['Test']))
{
$model = new Test();
$model->attributes = $_POST['Test'];
if($model->save())
{
$this->redirect('postTest');
}
}
$this->render('posttest', array('model'=>new Test()));
}
這樣可以將表單中的數據保存兩次到數據庫。
怎么了?
嘗試禁用ajax驗證。
在該視圖enableAjaxValidation
設置為false
。
實際上POST發生了兩次。 第一個Ajax驗證和第二個表單提交。 你可以在firefox中使用httpfox來確認它。
你可以試試這個
$model = new Test();
if(isset($_POST['Test']))
{
$model->attributes = $_POST['Test'];
if($model->save())
{
unset($_POST['Test']);
$this->redirect('postTest');
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.