Hi all,
I ´ve started to use Yii2 Basic one month ago, and now I was finish all that I want for the web page.
The next questions are based on basic application to make easier the explanation and considering that I have these views:
Home
About
Contact
Login
Question 1:
At this moment I want that the application allows to guest user to see home and for the others views redirect all guest to login view, and I don’t have idea how to obtain this result.
Question 2:
How I can reach these results after user was login with 3 different types of user:
Group 1: access to home, login and about
Group 2: access to home, login and contact
Group 3 (admin): access to all views
When I saw the code below in basic/view/layouts/main.php I suppose that the question 1 was resolved but without login I can access to all the views
<?php
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
Yii::$app->user->isGuest ?
['label' => 'Login', 'url' => ['/site/login']] :
['label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']],
],
]);
NavBar::end();
?>
I hope someone can help me with those questions.
Thanks.