后台菜单处理
加载一级菜单
public function index(){
//加载菜单
$menus = DB::table('xpcms_admin_menu')->where('pid',0)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
$data['menus'] = $menus;
return view('admins.home.index',$data);
}
渲染
<ul class="tree phpcn-clear" id="phpcn_nav_side">
@foreach ($menus as $menu)
<li>
<h2>
<span class="phpcn-icon" {{$menu->icon}}></span><label>{{$menu->title}}</label><i class="phpcn-r phpcn-icon phpcn-icon-down "></i>
</h2>
<template v-if="item.children!=undefined && item.children.length !== 0">
<dl>
<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>
</dl>
</template>
</li>
@endforeach
</ul>
转换成数组返回view
public function index(){
//加载菜单
$menus = DB::table('xpcms_admin_menu')->where('pid',0)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
foreach ($menus as $key => $val) {
$menus[$key] = (array)$val;
}
$data['menus'] = $menus;
return view('admins.home.index',$data);
}
渲染
<h2>
<span class="phpcn-icon" {{$menu['icon']}}></span><label>{{$menu['title']}}</label><i class="phpcn-r phpcn-icon phpcn-icon-down "></i>
</h2>
加载二级菜单
public function index(){
//加载菜单
$menus = DB::table('xpcms_admin_menu')->where('pid',0)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
foreach ($menus as $key => $val) {
$menus[$key] = (array)$val;
$children = DB::table('xpcms_admin_menu')->where('pid',$val->mid)->where('status',0)->where('ishidden',0)->orderBy('ord','asc')->get()->all();
$menus[$key]['children'] = $children;
}
$data['menus'] = $menus;
return view('admins.home.index',$data);
}
渲染
@foreach ($menu['children'] as $chd)
<dl>
<a href="javascript:;" onclick="menu_fire(this)" controller="{{$chd->controller}}" action="{{$chd->action}}">{{$chd->title}}</a>
</dl>
@endforeach
处理iframe跳转
function menu_fire(obj) {
var controller = $(obj).attr('controller');
var action = $(obj).attr('action');
var url = '/admins/' + controller + '/' + action;
url = url.toLowerCase();
alert(url);
//找到iframe
$('#main_frame').attr('src', url);
}
seo设置页面
seo保存数据
以json字符串的形式存入数据库
<script type="text/javascript">
function site_save(){
var title = $.trim($('input[name="title"]').val());
var keywords = $.trim($('input[name="keywords"]').val());
var descs = $.trim($('input[name="descs"]').val());
$.post('/admins/site/save_seo',{title:title,keywords:keywords,descs:descs,_token:$('input[name="_token"]').val()},function(res){
if(res.code>0){
return layer.alert(res.msg,{icon:2});
}else{
return layer.msg(res.msg);
}
},'json');
}
</script>
public function save_seo(Request $req)
{
$title = $req->title;
$keywords = $req->keywords;
$desc = $req->descs;
$key = 'site_seo';
$values = json_encode(array('title' => $title, 'keywords' => $keywords, 'descs' => $desc));
$item = DB::table('xpcms_sys_setting')->where('keys', $key)->first();
if ($item) {
DB::table('xpcms_sys_setting')->where('keys', $key)->update(array('values' => $values));
} else {
DB::table('xpcms_sys_setting')->insert(array('keys' => $key, 'values' => $values));
}
return json_encode(array('code' => 0, 'msg' => '保存成功'));
}
seo渲染数据
public function seo()
{
$data['seoset'] = DB::table('xpcms_sys_setting')->where('keys', 'site_seo')->first();
if ($data['seoset']) {
$data['seoset'] = (array) $data['seoset'];
$data['seoset']['values'] = json_decode($data['seoset']['values'], true);
}
return view('admins.site.seo', $data);
}
<div class="phpcn-input-inline">
<input type="text" name="title" placeholder="请输入网站标题" class="phpcn-input" value="{{$seoset['values']['title']}}">
</div>
区分ajax/浏览器地址栏请求
private function _norights($request,$msg){
// 检测访问method
// 如果是浏览器地址栏请求,直接返回$msg
// 如果是ajax请求,返回json
if($request->ajax()){
return json_encode(array('code'=>1,'msg'=>$msg));
}else{
return $msg;
}
}