潜入这个新的yii 2并且Im已经卡住了。我正在尝试用表单更新用户记录。原始记录正在窗体中加载,但更改窗体中的值不会更新记录。更新Yii 2中的记录
public function actionUserprofile()
{
$id = Yii::$app->user->identity->id;
$model = User::find()->where(['id' => $id])->one();
if($model->load(Yii::$app->request->post()) && $model->save())
{
Yii::$app->session->setFlash('success','You have updated your profile.');
}
return $this->render('userProfile', [
'model' => $model,
]);
}
//view form
<div>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'username')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'first_name')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'last_name')->textInput(['maxlength' => 255]) ?>
<div class="form-group">
<?= Html::submitButton('Submit',['class'=>'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
很可能它没有通过验证。显示模型规则,场景(如果有)以及您尝试保存的数据。 – arogachev 2015-04-02 16:00:33