Blogger Information
Blog 29
fans 0
comment 0
visits 19621
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp新闻实战笔记三(清除缓存和权限菜单)
牡丹飞
Original
616 people have browsed it

清除缓存

  1. 后台主页index.html加字体图标 http://www.fontawesome.com.cn/icons
    实际图标名称建议从\public\static\almasaeed2010\adminlte\plugins\fontawesome-free\css\all.css
  1. <a href="#" class="dropdown-item dropdown-footer">{$uname}</a>
  2. <div class="dropdown-divider"></div>
  3. <a href="{:url('/index/logout')}" class="dropdown-item dropdown-footer">
  4. <i class="fa fa-sign-out-alt" aria-hidden="true"></i>
  5. &nbsp;&nbsp;退出登陆
  6. </a>
  7. <div class="dropdown-divider"></div>
  8. <a href="javascript:;" onclick="clearCache(this)" class="dropdown-item dropdown-footer">
  9. <i class="fa fa-trash" aria-hidden="true"></i>
  10. &nbsp;&nbsp;清除缓存
  11. </a>
  1. 清除缓存——当前页js

    1. <!-- layui js -->
    2. <!-- <script src="/static/layui/layui.js"></script> -->
    3. <script src="{__LAYUI__}layui.js"></script>
    4. <script type="text/javascript">
    5. //layui弹出层
    6. layui.use("layer", function () {
    7. layer = layui.layer;
    8. });
    9. function clearCache(obj) {
    10. layer.confirm(
    11. "要清缓存吗?",
    12. { icon: 3, title: "知道" },
    13. function (index) {
    14. $.post({
    15. url: "index/clearCache",
    16. type: "post",
    17. success: function (res) {
    18. if (res.status == 1) {
    19. layer.msg(res.msg);
    20. } else {
    21. layer.msg(res.msg);
    22. }
    23. layer.close(index);
    24. },
    25. });
    26. },
    27. "json"
    28. );
    29. }
    30. </script>
  2. app\admin\controller\index.php控制器方法清除

    1. public function clearCache()
    2. {
    3. $运行目录 = app()->getRuntimePath();
    4. if(删除目录文件($运行目录))
    5. {
    6. $res = ['status'=>1,'msg'=>'清除成功'];
    7. return json($res);
    8. exit;
    9. }
    10. else
    11. {
    12. $res = ['status'=>0,'msg'=>'清除失败'];
    13. return json($res);
    14. exit;
    15. }
    16. }
  3. app\admin\common.php公共方法删除目录和文件

    1. if(!function_exists('删除目录文件'))
    2. {
    3. /**
    4. * 返回值:真或假
    5. */
    6. function 删除目录文件($删除目录)
    7. {
    8. $结果 = false;
    9. if(is_dir($删除目录))
    10. {
    11. if($打开目录 = opendir($删除目录))
    12. {
    13. while(false !== ($目录项 = readdir($打开目录)))
    14. {
    15. if($目录项 != '.' && $目录项 != '..')
    16. {
    17. $目录或文件 = $删除目录 .'\\' . $目录项;
    18. if(is_dir($目录或文件))
    19. {
    20. 删除目录文件($目录或文件);
    21. }
    22. else
    23. {
    24. unlink($目录或文件);
    25. }
    26. }
    27. }
    28. closedir($打开目录);
    29. $结果 = rmdir($删除目录);
    30. }
    31. }
    32. return $结果;
    33. }
    34. }

    权限菜单

  4. 删除没用的菜单仅留下 Dashboard和Widgets
  5. 数据表执行老师给的news.sql就可以了
  6. 后台查询数据
    1. public function index()
    2. {
    3. $用户号 = session('uid');
    4. $用户名 = session('uname');
    5. $用户权限号 = Db::name('users')
    6. ->alias('u')
    7. ->where('u.uid',$用户号)
    8. ->field('u.uid,u.uname,ar.rules')
    9. ->leftJoin('users_role ur','ur.uid = u.uid')
    10. ->leftJoin('auth_role ar','ar.id = ur.role_id')
    11. ->select()->toArray();
    12. $权限号 = array_column($用户权限号,'rules');
    13. $权限号 = explode(',',implode(',',$权限号));
    14. $菜单信息 = Db::name('auth_rule')
    15. ->field('id,name,title,pid')
    16. ->order('id','acs')
    17. ->where('is_menu',1)
    18. ->where('id','in',$权限号)
    19. ->select();
    20. dd($菜单信息);
    21. $用户信息 = ['uid'=>$用户号,'uname'=>$用户名];
    22. return view('index', $用户信息);
    23. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post