1. Go to this page and download the library: Download infoburp/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/ */
infoburp / yii2-user example snippets
// app/config/web.php
return [
'components' => [
// NOTE: in the yii2-advanced-app, the user component should be updated in
// 'frontend/config/main.php' and/or 'backend/config/main.php' (OR you can add it
// to 'common/config' if you remove it from frontend/backend)
'user' => [
'class' => 'app\modules\user\components\User',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => true,
'messageConfig' => [
'from' => ['[email protected]' => 'Admin'], // this is needed for sending emails
'charset' => 'UTF-8',
]
],
],
'modules' => [
'user' => [
'class' => 'app\modules\user\Module',
// set custom module properties here ...
],
],
];
// app/config/db.php
return [
'class' => 'yii\db\Connection',
// set up db info
];
if (!Yii::$app->user->can("admin")) {
throw new HttpException(403, 'You are not allowed to perform this action.');
}
// --- or ----
$user = User::findOne(1);
if ($user->can("admin")) {
// do something
};