PHP code example of andatech / yii2-user

1. Go to this page and download the library: Download andatech/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/ */

    

andatech / yii2-user example snippets


    'modules' => [
        ...
        'user' => [ //module id = 'user' only
            'class' => 'anda\user\Module',
            'loginBy' => 'db', //db or ldap
            'userUploadDir' => '@uploads', //real path
            'userUploadUrl' => '/uploads', //url path
            'userUploadPath' => 'user', //path after upload directory
            'admins' => ['admin', 'root'] //list username for manage users
        ],
        ...
    ],
    'components' => [
        ...
        'authManager' => [
            'class' => 'yii\rbac\DbManager'
        ],
        'user' => [
            'identityClass' => 'anda\user\models\User',
            'loginUrl' => ['/user/auth/login'],
            ...
        ],
        ...
    ],

Yii::$app->user->isGuest ?
    ['label' => 'Sign in', 'url' => ['/user/auth/login']] :
    ['label' => 'Sign out (' . Yii::$app->user->identity->username . ')',
        'url' => ['/user/auth/logout'],
        'linkOptions' => ['data-method' => 'post']],
['label' => 'Register', 'url' => ['/user/regist/signup'], 'visible' => Yii::$app->user->isGuest]

//Current user
$user = Yii::$app->user->identity;
print_r($user->profile->resultInfo);
//if use $user->profile->resultData in result = base user data

//another user
$user = \anda\user\models\User::findOne(2);
print_r($user->profile->resultInfo);
//if use $user->profile->resultData in result = base user data