Go [[step_2_-_create_crud_for_the_database|back]]

Now we will install the [[https://packagist.org/packages/amnah/yii2-user|**amnah/yii2-user**]] module.\\

Put ''%%"amnah/yii2-user": "^5.0"%%'' in the composer.json file then run ''composer update -vv''\\
This will install the module.\\

Edit ''config\web.php''
<code php>
    'components' => [
        'user' => [
            'class' => 'amnah\yii2\user\components\User',
            // 'identityClass' => 'app\models\User',
            // 'enableAutoLogin' => true,
        ],
        ...
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
            'messageConfig' => [
                'from' => ['admin@website.com' => 'Admin'], // this is needed for sending emails
                'charset' => 'UTF-8',
            ]
        ],
    ],
    'modules' => [
        'user' => [
            'class' => 'amnah\yii2\user\Module',
            // set custom module properties here ...
        ],
    ],
</code>

Run the migration file
<code>
php yii migrate --migrationPath=@vendor/amnah/yii2-user/migrations
</code>

Edit the //Nav::widgets// in ''views\layouts\main.php'' file
<code php>
echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'items' => [
        [
            'label' => 'Home',
            'url' => ['/site/index'],
            'linkOptions' => [],
        ],
        [
            'label' => 'About',
            'url' => ['/site/about'],
            'linkOptions' => [],
        ],
        [
            'label' => 'Contact',
            'url' => ['/site/contact'],
            'linkOptions' => [],
        ],
        [
            'label' => 'Guitars',
            'url' => ['/guitars'],
            'linkOptions' => [],
        ],
        [
            'label' => 'User',
            'url' => ['/user'],
            //    'img' => 'dist/img/user2-160x160.jpg',
            'visible' => (Yii::$app->user->can("admin")!= null),
        ],
        Yii::$app->user->isGuest ? (
                ['label' => 'Login', 'url' => ['/user/login']]
            ) : (
                '<li>'
                . Html::beginForm(['/user/logout'], 'post')
                . Html::submitButton(
                    'Logout (' . Yii::$app->user->identity->username . ')',
                    ['class' => 'btn btn-link logout']
                )
                . Html::endForm()
                . '</li>'
            ),
/*        [
                'label' => 'Dropdown',
                'items' => [
                [
                        'label' => 'Level 1 - Dropdown A',
                        'url' => '#'
                ],
                '<li class="divider"></li>',
                '<li class="dropdown-header">Dropdown Header</li>',
                [
                        'label' => 'Level 1 - Dropdown B',
                        'url' => '#'
                ]
                ]
        ] */
        ]  
]);
</code>

Go to [[step_4_-_setting_and_using_amnah_yii2_permissions|Setting User Permissions]]

Back to [[yii|Yii Main Index]]