私はこれについて異なる実装を見たことがありますが、私の特定のコード$this->refresh();
で動作しないか、多分私はどこに私の場合にそれを置くのか分からない。誰かが私を助けることができる?フォームの再送信を防止するYii 2
ここは私のコントローラの動作です。
public function actionIndex()
{
// if (!Yii::$app->user->isGuest) {
// return $this->goHome();
// }
$model = new LoginForm();
$model = new LoginForm();
if (($model->load(Yii::$app->request->post()) && $model->login()) || (!Yii::$app->user->isGuest)) {
$this->layout = 'userlayout';
// $this->refresh();
return $this->render('mainpage', [
'model' => $model,
//return $this->goBack();
]);
//$this->refresh();
}
return $this->render('index', [
'model' => $model,
]);
}
編集:私は、以下の勧告に基づいて、私のコードを編集した、これは完全な試練のコードです。
public function actionIndex()
{
if (!Yii::$app->user->isGuest) {
//return $this->goHome();
$this->redirect('site/main',302);
// $this->layout = 'userlayout';
// return $this->render('mainpage');
}
// $model = new LoginForm();
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
// $this->layout = 'userlayout';
//return $this->goBack();
$this->redirect('site/main',302);//\Yii::$app->urlManager->createUrl("test/show") $this->redirect('/user/index',302);
//return $this->render('mainpage');
}
// if (($model->load(Yii::$app->request->post()) && $model->login()) || (!Yii::$app->user->isGuest)) {
// $this->layout = 'userlayout';
// // $this->refresh();
// return $this->render('mainpage', [
// 'model' => $model,
// //return $this->goBack();
// ]);
// //$this->refresh();
// }
return $this->render('index', [
'model' => $model,
]);
}
論理の最終目標は何か教えてください。 – g9m29
これは通常のログインフォームです。それは、yiiは私が持っていないテーブルの特定の列を必要とするためです。ここでのロジックは、ログインフォーム>ログイン後にメインページを表示>ユーザーがページを更新しようとすると、再送のプロンプトが表示されます(これを削除したいと思います)。 – user827391012
別のページに誘導し、フォームの再送信を取り除くログインを実装するためのより良い方法がある場合は、それも高く評価されます。 – user827391012