12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-02-17
- // +—————————————————————————————————————————————————————————————————————
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\Db;
- use app\admin\model\AdminMenuModel;
- class IndexController extends AdminBaseController
- {
- public function initialize()
- {
- $adminSettings = cmf_get_option('admin_settings');
- if (empty($adminSettings['admin_password']) || $this->request->path() == $adminSettings['admin_password']) {
- $adminId = cmf_get_current_admin_id();
- if (empty($adminId)) {
- session("__LOGIN_BY_CMF_ADMIN_PW__", 1);//设置后台登录加密码
- }
- }
- parent::initialize();
- }
- /**
- * 后台首页
- */
- public function index()
- {
- $content = hook_one('admin_index_index_view');
- if (!empty($content)) {
- return $content;
- }
- $adminMenuModel = new AdminMenuModel();
- $menus = cache('admin_menus_' . cmf_get_current_admin_id(), '', null, 'admin_menus');
- if (empty($menus)) {
- $menus = $adminMenuModel->menuTree();
- cache('admin_menus_' . cmf_get_current_admin_id(), $menus, null, 'admin_menus');
- }
- $this->assign("menus", $menus);
- $result = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select();
- $menusTmp = array();
- foreach ($result as $item){
- //去掉/ _ 全部小写。作为索引。
- $indexTmp = $item['app'].$item['controller'].$item['action'];
- $indexTmp = preg_replace("/[\\/|_]/","",$indexTmp);
- $indexTmp = strtolower($indexTmp);
- $menusTmp[$indexTmp] = $item;
- }
- $this->assign("menus_js_var",json_encode($menusTmp));
- //$admin = Db::name("user")->where('id', cmf_get_current_admin_id())->find();
- //$this->assign('admin', $admin);
- return $this->fetch();
- }
- }
|