model->save() Not Working In Yii2

后端 未结 10 1550
情歌与酒
情歌与酒 2020-12-06 01:10

Previously, I was not using $model->save() function for inserting or updating any data. I was simply using createCommand() to execute query and

10条回答
  •  Happy的楠姐
    2020-12-06 02:00

    if your column type in your table is "integer" and your data is "string" you may see tis error.You should check your data type and try again.

    I suppose that your column type is integer, you should write the following code:

    $model->created_at=time();//1499722038
    $model->save(); 
    

    but your column type is string, you should write the following code:

    $model->created_at=date('d/m/Y');//11/07/2017
    $model->save(); 
    

提交回复
热议问题