예제 #1
0
 /**
  * Creates a new Menu model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionAdd()
 {
     //菜单权限检测
     Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login');
     $model = new Menu();
     if ($model->load(Yii::$app->request->post())) {
         $model->create_time = time();
         if ($model->save()) {
             return $this->redirect(['index']);
         } else {
             return $this->render('add', ['model' => $model]);
         }
     } else {
         $data = $model->menu();
         $parent = [];
         foreach ($data as $v) {
             if ($v['parent_id'] == 0) {
                 $parent[$v['id']] = $v['menu_name'];
             }
         }
         $parent[0] = '顶级菜单';
         return $this->render('add', ['model' => $model, 'parent' => $parent]);
     }
 }
예제 #2
0
 <?php 
use yii\helpers\Html;
use backend\models\Menu;
use yii\helpers\Url;
use backend\assets\AppAsset;
AppAsset::register($this);
$mMenu = new Menu();
$uri = Yii::$app->request->pathInfo;
$uri = substr_count($uri, '/') == 2 ? substr($uri, 0, strrpos($uri, '/')) : $uri;
$session = Yii::$app->session;
$session->isActive ? '' : $session->open();
$admin = $session->get('admin');
$session->close();
$ids = json_decode($admin['auth']);
$menu = $mMenu->menu();
$sub_parent_id = '';
$parent_id = '';
$son_id = '';
foreach ($menu as $key => $value) {
    if ($value['menu_link'] == $uri) {
        if ($value['menu_depth'] >= 2) {
            $sub_parent_id = $value['parent_id'];
            $parent_id = $mMenu->get_menu_by_parent_id($sub_parent_id, 2)->id;
            $son_id = $mMenu->get_menu_by_parent_id($sub_parent_id, 1)->id;
        } else {
            $parent_id = $value['parent_id'];
            $son_id = $value['id'];
        }
        break;
    }
}
예제 #3
0
<?php

use yii\helpers\Html;
use backend\models\Menu;
use yii\helpers\Url;
use backend\assets\AppAsset;
AppAsset::register($this);
$mMenu = new Menu();
$session = Yii::$app->session;
$session->isActive ? '' : $session->open();
$admin = $session->get('admin');
$session->close();
$ids = json_decode($admin['auth']);
$menu = $mMenu->menu($ids);
$parent_id = '';
$son_id = '';
foreach ($menu as $key => $value) {
    if ($value['menu_link'] == Yii::$app->request->pathInfo) {
        $parent_id = $value['parent_id'];
        $son_id = $value['id'];
        break;
    }
}
$icon = ['首页管理' => 'ti-home', '产品' => 'fa fa-cubes', '设置' => 'ti-settings', '主页' => 'ti-user'];
// print_r(array_column($menu, 'menu_link', 'id', 'menu_name'));
// $menu = $mMenu->menu();
$this->beginPage();
?>
<!DOCTYPE html>
<!-- Template Name: Clip-Two - Responsive Admin Template build with Twitter Bootstrap 3.x | Author: ClipTheme -->
<!--[if IE 8]><html class="ie8" lang="en"><![endif]-->
예제 #4
0
 /**
  * 修改管理员
  *
  * @param array $_POST[] 管理员修改数据
  */
 public function actionUpdate()
 {
     //菜单权限检测
     Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login');
     $mAdmin = new Admin();
     if ($params = Yii::$app->request->post()) {
         //验证
         if (empty($params['user_name'])) {
             Yii::$app->util->msg('参数错误');
         }
         if (empty($params['password']) && empty($params['repassword'])) {
             $options = ['id' => $params['id'], 'user_name' => $params['user_name'], 'auth' => isset($params['auth']) ? json_encode($params['auth']) : ''];
         } else {
             if ($params['password'] != $params['repassword']) {
                 Yii::$app->util->msg('两次密码不一致');
             } else {
                 $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
                 $salt = substr(str_shuffle($str), 0, 8);
                 $options = ['id' => $params['id'], 'user_name' => $params['user_name'], 'salt' => $salt, 'password' => Yii::$app->util->passwordEncode($params['password'], $salt), 'auth' => isset($params['auth']) ? json_encode($params['auth']) : ''];
             }
         }
         if ($mAdmin->store($options)) {
             return $this->redirect('admin-list');
         } else {
             Yii::$app->util->msg('入库错误');
         }
     } else {
         $id = Yii::$app->request->get('id', 0);
         $one = $mAdmin->getAdminById($id);
         if (!$one) {
             return $this->redirect('admin-list');
         } else {
             $mMenu = new Menu();
             $data = $mMenu->menu();
             $auth = json_decode($one['auth']);
             if (!empty($auth)) {
                 foreach ($data as $k => $v) {
                     if (in_array($v['id'], $auth)) {
                         $data[$k]['checked'] = 'checked';
                     } else {
                         $data[$k]['checked'] = '';
                     }
                 }
             }
             return $this->render('update', ['data' => $data, 'one' => $one]);
         }
     }
 }