在更新操作后,Yii2没有重定向到索引页


Yii2 doesn't redirect to index page after update action

我的更新按钮代码:

<div class="form-group">
    <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

在updateAction中我有:

if ($model->load(Yii::$app->request->post()) && $model->save()) {
    return $this->redirect(['index']);
} else {
    return $this->render('update']);
}

,但当我更新我的表单,按下更新按钮,它更新值,但它返回给我更新页,不重定向到索引。有什么问题吗?

或者

这个- $model->load(Yii::$app->request->post())false,或者- $model->save() = false

检查你是否用你需要的类初始化模型(而不是另一个),并检查$model->errors内容,也许你有一些字段不在表单上,不可见,但包含错误。