How to create Loginform with popup in yii2-Framework
How to create Loginform with popup in yii2-Framework
// frontend/views/layouts/header.php
// Ajax script
// Edit frontend/controllers/SiteController.php
// frontend/views/site/login.php
// frontend/views/layouts/header.php
// Ajax script
// Edit frontend/controllers/SiteController.php
use yii\bootstrap\ActiveForm; class SiteController extends Controller { public function actionLogin() { $model = new LoginForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->login()) { $session = Yii::$app->session; $session->set('username', $_POST['LoginForm']['username']); $session->set('password', $_POST['LoginForm']['password']); return $this->goHome(); } else { return $this->renderAjax( 'login', [ 'model' => $model ] ); } return $this->renderAjax( 'login', [ 'model' => $model ] ); } }
// frontend/views/site/login.php
<?php use yii\helpers\Url; use yii\helpers\Html; use yii\bootstrap\ActiveForm; ?>
No comments: