博客列表 >综合实战第八课:后台系统开发1-PHP培训九期线上班

综合实战第八课:后台系统开发1-PHP培训九期线上班

渡劫小能手
渡劫小能手原创
2020年01月15日 22:59:45598浏览

后台菜单处理

加载一级菜单

  1. public function index(){
  2. //加载菜单
  3. $menus = DB::table('xpcms_admin_menu')->where('pid',0)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
  4. $data['menus'] = $menus;
  5. return view('admins.home.index',$data);
  6. }

渲染

  1. <ul class="tree phpcn-clear" id="phpcn_nav_side">
  2. @foreach ($menus as $menu)
  3. <li>
  4. <h2>
  5. <span class="phpcn-icon" {{$menu->icon}}></span><label>{{$menu->title}}</label><i class="phpcn-r phpcn-icon phpcn-icon-down "></i>
  6. </h2>
  7. <template v-if="item.children!=undefined && item.children.length !== 0">
  8. <dl>
  9. <a href="javascript:;" v-for="ch in item.children" v-bind:data="ch.url" onclick="menu_fire(this)" v-bind:controller="ch.controller" v-bind:action="ch.action" v-text="ch.title"></a>
  10. </dl>
  11. </template>
  12. </li>
  13. @endforeach
  14. </ul>

转换成数组返回view

  1. public function index(){
  2. //加载菜单
  3. $menus = DB::table('xpcms_admin_menu')->where('pid',0)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
  4. foreach ($menus as $key => $val) {
  5. $menus[$key] = (array)$val;
  6. }
  7. $data['menus'] = $menus;
  8. return view('admins.home.index',$data);
  9. }

渲染

  1. <h2>
  2. <span class="phpcn-icon" {{$menu['icon']}}></span><label>{{$menu['title']}}</label><i class="phpcn-r phpcn-icon phpcn-icon-down "></i>
  3. </h2>

加载二级菜单

  1. public function index(){
  2. //加载菜单
  3. $menus = DB::table('xpcms_admin_menu')->where('pid',0)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
  4. foreach ($menus as $key => $val) {
  5. $menus[$key] = (array)$val;
  6. $children = DB::table('xpcms_admin_menu')->where('pid',$val->mid)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
  7. $menus[$key]['children'] = $children;
  8. }
  9. $data['menus'] = $menus;
  10. return view('admins.home.index',$data);
  11. }

渲染

  1. @foreach ($menu['children'] as $chd)
  2. <dl>
  3. <a href="javascript:;" onclick="menu_fire(this)" controller="{{$chd->controller}}" action="{{$chd->action}}">{{$chd->title}}</a>
  4. </dl>
  5. @endforeach

处理iframe跳转

  1. function menu_fire(obj) {
  2. var controller = $(obj).attr('controller');
  3. var action = $(obj).attr('action');
  4. var url = '/admins/' + controller + '/' + action;
  5. url = url.toLowerCase();
  6. alert(url);
  7. //找到iframe
  8. $('#main_frame').attr('src', url);
  9. }

seo设置页面

seo保存数据

以json字符串的形式存入数据库

  1. <script type="text/javascript">
  2. function site_save(){
  3. var title = $.trim($('input[name="title"]').val());
  4. var keywords = $.trim($('input[name="keywords"]').val());
  5. var descs = $.trim($('input[name="descs"]').val());
  6. $.post('/admins/site/save_seo',{title:title,keywords:keywords,descs:descs,_token:$('input[name="_token"]').val()},function(res){
  7. if(res.code>0){
  8. return layer.alert(res.msg,{icon:2});
  9. }else{
  10. return layer.msg(res.msg);
  11. }
  12. },'json');
  13. }
  14. </script>
  1. public function save_seo(Request $req)
  2. {
  3. $title = $req->title;
  4. $keywords = $req->keywords;
  5. $desc = $req->descs;
  6. $key = 'site_seo';
  7. $values = json_encode(array('title' => $title, 'keywords' => $keywords, 'descs' => $desc));
  8. $item = DB::table('xpcms_sys_setting')->where('keys', $key)->first();
  9. if ($item) {
  10. DB::table('xpcms_sys_setting')->where('keys', $key)->update(array('values' => $values));
  11. } else {
  12. DB::table('xpcms_sys_setting')->insert(array('keys' => $key, 'values' => $values));
  13. }
  14. return json_encode(array('code' => 0, 'msg' => '保存成功'));
  15. }

seo渲染数据

  1. public function seo()
  2. {
  3. $data['seoset'] = DB::table('xpcms_sys_setting')->where('keys', 'site_seo')->first();
  4. if ($data['seoset']) {
  5. $data['seoset'] = (array) $data['seoset'];
  6. $data['seoset']['values'] = json_decode($data['seoset']['values'], true);
  7. }
  8. return view('admins.site.seo', $data);
  9. }
  1. <div class="phpcn-input-inline">
  2. <input type="text" name="title" placeholder="请输入网站标题" class="phpcn-input" value="{{$seoset['values']['title']}}">
  3. </div>

区分ajax/浏览器地址栏请求

  1. private function _norights($request,$msg){
  2. // 检测访问method
  3. // 如果是浏览器地址栏请求,直接返回$msg
  4. // 如果是ajax请求,返回json
  5. if($request->ajax()){
  6. return json_encode(array('code'=>1,'msg'=>$msg));
  7. }else{
  8. return $msg;
  9. }
  10. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议