【发布时间】:2016-04-14 12:25:58
【问题描述】:
创建新记录时,我需要将列值更新 + 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,
]);
}
}
我做错了什么请指导:)
【问题讨论】:
-
是否因某种原因对确切的错误消息或意外行为进行了分类?
-
我没有收到任何错误,但它也没有返回任何结果
-
如果似乎最好在成功
save()记录后立即更新计数器。if ($model->save()) { /*update counter and redirec*/ } -
@SiZE.. 它也不起作用
-
@SiZE 如何使用`Yii::$app->db->createCommand("UPDATE room_types SET total_booked = total_booked + 1 WHERE room_type = '$model->room_type'")-> execute();` 查询行为?
标签: php mysql activerecord yii yii2