Beginner - Login Page

Hello , How I can make Login page that want from every Guest to type his username and password and after he Sign In , to be redirected to the website and then he can see the content in the website . (if he is a Guest ,he see only the Login Form window)

Thank you in advance!

You can try "yii2-app-advanced" project template, which provides you with a set of common user management features like logging in, signing up, resetting password, … etc.

Or you may try "yii2-app-practical" series from kartik-v. (google it please).

ok but is there a way to do it with Yii2 Basic ? I must create a new layout , and how I must manage to get this login page when I enter the website?

there plenty of ways to do it, simple one you can check for user data before rendering the home page

in your sitecontroller.php


public function actionIndex()

{

	if (Yii::$app->user->isGuest) {

		return $this->redirect("/login_page");

	}

	

	.........

}

And also check "Access Control Filter" in the guide.

http://www.yiiframework.com/doc-2.0/guide-security-authorization.html#access-control-filter

You can deny access to "index" and other pages for guest users, and it will automatically send the guest to "login" page.

Thanks for the info , I did it :)