hy-farm/muchang/backend/controllers/RbacController.php
2026-05-29 19:54:56 +08:00

50 lines
1.1 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: zn
* Date: 2017/6/12
* Time: 11:29
*/
namespace app\controllers;
use Yii;
use yii\web\Controller;
class RbacController extends Controller
{
public function actionInit()
{
//admin
// $this->createPermission('/*');
// $this->createRole('admin');
// self::createEmpowerment(['name' => 'admin', 'description' => '/*']);
}
private function createPermission($item)
{
$auth = Yii::$app->getAuthManager();
$createPost = $auth->createPermission($item);
$createPost->description = '创建了 ' . $item . ' 许可';
$auth->add($createPost);
}
private function createRole($item)
{
$auth = Yii::$app->authManager;
$role = $auth->createRole($item);
$role->description = '创建了 ' . $item . ' 角色';
$auth->add($role);
}
private static function createEmpowerment($items)
{
$auth = Yii::$app->authManager;
$parent = $auth->createRole($items['name']);
$child = $auth->createPermission($items['description']);
$auth->addChild($parent, $child);
}
}