我有一個更新的形式,它包含這些代碼 查看Yii2:在DB的記錄沒有更新時,在HTML中改變值選擇
<?= $form->field($model, 'type')->dropDownList([
'0' => 'Individual',
'1' => 'Entity',
]) ?>
行動
public function actionUpdate()
{
$id = Yii::$app->user->id;
$model = Page::find()->where(['user_id'=>$id])->one();
if (!Yii::$app->user->can('UpdateOwnPage',['page'=>$model]))
{
throw new ForbiddenHttpException("You have no access to this page.");
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect('page/'.$model->url);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
但是我的DB表中的值仍然是0,它根本沒有改變。什麼問題?
這只是一個表單域...顯示提交的代碼和保存的操作.. – scaisEdge
我的錯,我忘了它。 – yutsura
你能顯示你的頁面模型嗎?驗證規則,您是否也保存方法成功? –