PHP code example of binn / yii2-auth

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

    

binn / yii2-auth example snippets


return [
    'components' => [
        'authManager' => [
            'class' => 'auth\components\DbManager', // or 'auth\components\PhpManager'
        ],
        // ...
    ],
    'modules' => [
        'auth' => [
            'class' => 'auth\Module',
        ],
    ],
];

'auth' => array(
  'userClass' => Yii::$app->user->identityClass, // the name of the user model class.
  'userIdColumn' => 'id', // the name of the user id column.
  'userNameColumn' => 'name', // the name of the user name column.
  'applicationControllers' => [], // the path to controllers files that will be using for generates permissions.
  'admin' => [], // users with full access to module.
  'accessFilterBehavior' => [], Configuration for custom access filter.
),

if (Yii::$app->user->can('itemName')) // itemName = name of the operation
{
  // access is allowed.
}

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
                'rules' => [
        		    [
        			    'allow' => true,
        			    'actions' => ['error', 'login', 'logout'],
                    ],
                    [
                        'allow' => true,
                        'roles' => [$this->getRuleName($this->action->id)],
                    ],
                    [
                        'allow' => true,
                        'matchCallback' => function () {
                            return !Yii::$app->user->isGuest ? !empty(Yii::$app->user->identity->isAdmin) : false;
                    },
                ],
            ],
        ],
    ];
}