一个为ant design 设计的菜单组件, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist toshcn/yii2-ant-menu "*"
or add, (*4)
"toshcn/yii2-ant-menu": "*"
to the require section of your composer.json
file., (*5)
Usage
配置应用组件:如common->config->main.php, (*6)
'components' => [
'menuManager' => [
'class' => 'toshcn\yii2\menu\MenuManager',
'cache' = 'cache',
'cacheKey' => 'menu_cache_key',
'expire' => 3600,
'userTable' => '{{%user}}',
'superAdminGroupId' => 1
],
]
配置命令行: 基础模板在config->console.php,高级模板在console->config->main.php, (*7)
'controllerMap' => [
'menu' => [
'class' => 'toshcn\yii2\menu\commands\Menu',
],
],
运行数据迁移:, (*8)
php yii migrate --migrationPath=@vendor/toshcn/yii2-ant-menu/src/migrations
为用户表添加group_id
字段, (*9)
php yii menu/add-user-group-id-column
添加一个用户组:, (*10)
Yii::$app->menuManager->addGroup('user', '用户组说明:普通用户组');
添加一个菜单:, (*11)
$parentId = 0;
Yii::$app->menuManager->addMenu('menu_name', 'path', $parentId, 'icon');
给用户组分配一个菜单:, (*12)
$menuId = 1;
$groupId = 1;
Yii::$app->menuManger->assignMenu($menuId, $groupId);