1. Go to this page and download the library: Download jlorente/yii2-roles 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/ */
namespace common\models;
use jlorente\roles\models\RoleableTrait;
use jlorente\roles\models\RoleableInterface;
class User extends yii\db\ActiveRecord implements RoleableInterface {
use RoleableTrait;
//class content...
}
$user = new User();
jlorente\roles\models\Role::sAssign($user, 'Admin');
jlorente\roles\models\Role::sAssign($user, 'User');
$user->save();