一,登录成功后跳转页面
Login\index.php
$.post("http://localhost/tp6layui/public/index.php/bews/Login/login",$('form').serialize(),function(res){ // 登录成功 if(res.code==0){ layer.msg(res.msg,{'icon':1}); setTimeout(function(){ window.location.href="http://localhost/tp6layui/public/index.php/bews/index/index"; },1000); }
controller目录下新建Index.php,并写下function index,对应view目录下的Index目录的index.php
<?php namespace app\bews\controller; use think\App; use think\facade\View; use think\facade\Db; use think\facade\Cookie; class Index { public function index(){ return View::fetch(); } }
view目录下的Index目录的index.php注意修改样式等静态文件的路径
二,左侧菜单
class Index { public function index(){ // 获取数据左侧菜单的树状结构 $where = [['status','=',1]]; $menus = Db::table('admin_sys_menu')->order('type,sort DESC')->where($where)->select()->toArray(); $tree = []; foreach ($menus as $menus_v){ if($menus_v['parent_id'] == 0){ $tree[$menus_v['smid']] = $menus_v; }else{ $tree[$menus_v['parent_id']]['children'][] = $menus_v; } } // print_r($tree); // 模板变量赋值 View::assign([ 'menu' => $tree ]); return View::fetch(); }
bews目录下的view目录下的Index目录下的index.php
<!-- 侧边菜单 --> <div class="layui-side layui-side-menu"> <div class="layui-side-scroll"> <div class="layui-logo" lay-href=""> <span>后台管理系统</span> </div> <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu"> {volist name="menu" id="vo"} <li data-name="" data-jump="" class="layui-nav-item"> <a href="javascript:;" lay-tips="系统配置" lay-direction="2"> <i class="layui-icon layui-icons layui-icon-set"></i> <cite>{$vo.label}</cite> </a> {if(isset($vo['children']))} <dl class="layui-nav-child"> <dd data-name="" data-jump="/"> {volist name="vo['children']" id="voo"} <a href="javascript:;" οnclick="menuFire('{$voo.src}')"> <i class="layui-icon layui-icons layui-icon-group"></i>{$voo['label']} </a> {/volist} </dd> </dl> {/if} </li> {/volist} </ul> </div> </div>