Files
sentcms/app/controller/admin/Menu.php

89 lines
2.0 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\Model\Menu as MenuModel;
class Menu extends Admin{
/**
* @title 系统首页
*/
public function index(){
if($this->request->isAjax()){
$tree = $this->request->param('tree', 0);
$menu = new MenuModel();
$map = array();
$res = $menu->where($map)->order('sort asc, id asc')->select();
$list = $res->toArray();
if($tree){
if (!empty($list)) {
$tree = new \com\Tree();
$list = $tree->toFormatTree($list);
}
}
$this->data['data'] = $list;
return $this->data;
}
}
/**
* @title 编辑菜单
*/
public function edit(){
$menu = new MenuModel();
if($this->request->isAjax()){
$data = $this->request->post();
$result = $menu->where('id', $data['id'])->save($data);
if (false !== $result) {
$this->data['code'] = 0;
$this->data['msg'] = '更新成功!';
}else{
$this->data['code'] = 1;
$this->data['msg'] = '更新失败!';
}
return $this->data;
}else{
$id = $this->request->param('id', 0);
if (!$id) {
return $this->error('非法操作!');
}
$info = $menu->where('id', $id)->find();
$this->data['data'] = array('info'=>$info);
return $this->data;
}
}
/**
* @title 添加菜单
*/
public function add(){
if($this->request->isAjax()){
return $this->data;
}else{
$this->data['template'] = 'edit';
return $this->data;
}
}
/**
* @title 移除菜单
*/
public function remove(){
if($this->request->isAjax()){
return $this->data;
}
}
}