Yii2 選單menu管理

2022-08-15 02:15:12 字數 1920 閱讀 9793

menu表是根據許可權來控制後台選單的顯示和隱藏的。

先來看看表結構:

-- ----------------------------  

-- table structure for yc_menu

-- ----------------------------

drop table if exists `yc_menu`;

create table `yc_menu` (

`id` int(11) not null auto_increment,

`name` varchar(128) not null,

`parent` int(11) default null,

`route` varchar(256) default null,

`order` int(11) default null,

`data` text,

primary key (`id`),

key `parent` (`parent`),

key `name` (`name`),

key `route` (`route`(255)),

key `order` (`order`),

constraint `dh_menu_ibfk_1` foreign key (`parent`) references `dh_menu` (`id`) on delete set null on update cascade

) engine=innodb auto_increment=1 default charset=utf8 comment='系統管理員選單許可權表';

這裡詳細介紹幾個主要的字段:

name 是選單的名稱;

parent 是父類選單的名稱,留空則表示頂級選單;

route 指的是選單的url;

在資料庫裡的表現:

在頁面上的表現:

使用方式:

home

if(!empty($p_menu['items']))

$url_items=$item_arr[1];

}if(isset($url_arr[1]) && in_array($url_arr[1], $url_items))

?>

>

">

">

=$p_menu['label']?>

<?php if(!empty($p_menu['items'])) ?>

<?php }else} ?>

這裡使用到啦yii2-admin下的menuhelper類getassignedmenu方法,該方法用於獲取使用者對應的選單資訊.

在config\params.php下配置

return [

'adminemail' => '[email protected]',

'mdm.admin.configs' => [

'db' => 'db',

'menutable' => '}',

'cache' => null,

'cacheduration' => 3600

],];

最終顯示結果:

Yii2 例項管理

yii2框架沒有提供類似zendframework3中提供的servicemanager.那麼yii2框架是如何管理物件例項的呢?長時間使用yii2框架的童鞋一定已經適應了物件中的public變數,以及乙個來自yii base component的 set 魔術方法來完成物件構造的過程,但是新鳥如何...

yii2框架 yii2自身的自動載入 三

上一節說完了composer的自動載入,下面我們來說一下yii2自身的自動載入。在我們的入口檔案,例如index.php,如下 comment out the following two lines when deployed to production defined yii debug or d...

yii2框架 yii2的asset資源包 十一

link license license use yii web assetbundle author qiang xue since 2.0 定義按需載入css方法,注意載入順序在最後 public static function addcss view,cssfile 將需要載入的檔案已陣列聚合...