控制器中的Yii2更新查询不工作
我正在尝试更新“页面”列,但它不起作用。我只想通过将数据从4更改为5来更新一列。数据类型为整数 看法 一,。使用 当为true或false时,此方法将调用控制器中的Yii2更新查询不工作,yii2,Yii2,我正在尝试更新“页面”列,但它不起作用。我只想通过将数据从4更改为5来更新一列。数据类型为整数 看法 一,。使用 当为true或false时,此方法将调用 public function actionUpdateStatus($id) { $model = $this->findModel($id); $model->page = 5; if ($model->save(true, ['page'])) { $this-&g
public function actionUpdateStatus($id)
{
$model = $this->findModel($id);
$model->page = 5;
if ($model->save(true, ['page'])) {
$this->redirect(array('view', 'id' => $model->id));
}
return $this->redirect(['my-obituary']);
}
二,。使用
当不需要数据验证并且只需要更新一小部分属性时,此方法是一种快捷方式。您可以将要更新的属性指定为名称列表或名称-值对。如果是后者,则相应的属性值将被修改。然后,该方法将指定的属性保存到数据库中
请注意,此方法不会执行数据验证,也不会触发事件
public function actionUpdateStatus($id)
{
$model = $this->findModel($id);
$model->page = 5;
if ($model->updateAttributes(['page' => 5])) {
$this->redirect(array('view', 'id' => $model->id));
}
return $this->redirect(['my-obituary']);
}
是的,它通过使用两种解决方案工作。非常感谢。
public function actionUpdateStatus($id)
{
$model = $this->findModel($id);
$model->page = 5;
if ($model->save(true, ['page'])) {
$this->redirect(array('view', 'id' => $model->id));
}
return $this->redirect(['my-obituary']);
}
public function actionUpdateStatus($id)
{
$model = $this->findModel($id);
$model->page = 5;
if ($model->updateAttributes(['page' => 5])) {
$this->redirect(array('view', 'id' => $model->id));
}
return $this->redirect(['my-obituary']);
}