Blogger Information
Blog 37
fans 0
comment 0
visits 20792
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
综合实战第八课:后台系统开发1-PHP培训九期线上班
渡劫小能手
Original
592 people have browsed it

后台菜单处理

加载一级菜单

  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. }
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:加油, 课程越是到最后, 越精彩
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!