数据两次保存到数据库中 [英] data is saved twice to the database

查看:30
本文介绍了数据两次保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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()));
}

这是将来自表单的数据两次保存到数据库中.

This is saving the data which coming from a form twice to the database.

怎么了?

推荐答案

尝试禁用 ajax 验证.

Try disabling ajax validation.

在该视图中将 enableAjaxValidation 设置为 false.

Set enableAjaxValidation to false in that view.

实际上 POST 发生了两次.第一个 Ajax 验证和第二个表单提交.您可以通过在 Firefox 中使用 httpfox 来确认.

Actually there POST happens two times. First Ajax validation and second form submit. You can confirm it by using httpfox in firefox.

这篇关于数据两次保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆