PHP code example of filsh / yii2-user

1. Go to this page and download the library: Download filsh/yii2-user library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

filsh / yii2-user example snippets


// app/config/web.php
return [
    'components' => [
        'user' => [
            'class' => 'filsh\yii2\user\components\User',
        ],
        'mail' => [
            // set up mail for emails
        ]
    ],
    'modules' => [
        'user' => [
            'class' => 'filsh\yii2\user\Module',
            // set custom module properties here ...
        ],
    ],
];
// app/config/db.php
return [
        'class' => 'yii\db\Connection',
        // set up db info
];
 yii migrate --migrationPath=@vendor/filsh/yii2-user/migrations

// app/views/layouts/main.php

'items' => [
    ['label' => 'Home', 'url' => ['/site/index']],
    ['label' => 'About', 'url' => ['/site/about']],
    ['label' => 'Contact', 'url' => ['/site/contact']],
    ['label' => 'User', 'url' => ['/user']],
    Yii::$app->user->isGuest ?
        ['label' => 'Login', 'url' => ['/user/login']] :
        ['label' => 'Logout (' . Yii::$app->user->displayName . ')',
            'url' => ['/user/logout'],
            'linkOptions' => ['data-method' => 'post']],
],

if (!Yii::$app->user->can("admin")) {
    throw new HttpException(403, 'You are not allowed to perform this action.');
}
// --- or ----
$user = User::findOne(1);
$user->can("admin");

// app/config/web.php
'components' => [
    'user' => [
        'class' => 'app\components\MyUser',
    ],
],
'modules' => [
    'user' => [
        'class' => 'app\modules\MyModule',
        'controllerMap' => [
            'default' => 'app\controllers\MyDefaultController',
        ],
        'modelClasses'  => [
            'Profile' => 'app\models\MyProfile',
        ],
        'viewPath'      => '@app/views/user', // file example: @app/views/user/default/profile.php
        'emailViewPath' => '@app/mails',      // file example: @app/mails/confirmEmail.php
    ],
],

// app/config/console.php
'modules' => [
    'user' => [
        'class' => 'filsh\yii2\user\Module',
    ],
],
 yii user/copy

// app/config/web.php + app/config/console.php
'modules' => [
    'user' => [
        'class' => 'app\modules\user\Module',
    ],
],
filsh\yii2\user
app\modules\user