我需要更新由+ 1列的值时,新记录获得创建:Yii2:无法更新列值的+ 1
public function actionCreate()
{
$model = new CreateBookings();
if ($model->load(Yii::$app->request->post())) {
Yii::$app->db->createCommand("UPDATE room_types SET total_booked = total_booked + 1 WHERE room_type = '$model->room_type' ")->execute();
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
我在做什么错了,请指导:)
被归类为某种原因确切的错误消息或意外行为? – Shadow
即时消息没有得到任何错误,但是,它不返回任何结果 – JKLM
如果似乎最好在成功save()记录后更新计数器。 'if($ model-> save()){/ * update counter and redirec * /}' – SiZE