亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

實現(xiàn)菜單功能的增刪該查

原創(chuàng) 2019-05-07 23:37:02 241
摘要:<?php /**  * Created by PhpStorm.  * User: Jason  * Date: 2019/5/5  * Time: 23:29  */ namespace app\admin\controller; us
<?php
/**
 * Created by PhpStorm.
 * User: Jason
 * Date: 2019/5/5
 * Time: 23:29
 */

namespace app\admin\controller;

use Util\SysDb;
use think\facade\Request;
use app\admin\model\AdminModel;

class Menu extends Base
{
    public function index(){
        $data['lists'] = SysDb::getnstance()->table('admin_menus')->order('ord asc')->lists();
        return $this->fetch('',$data);
    }

    // 添加菜單
    public function add()
    {
        return $this->fetch();
    }

    // 添加操作
    public function doAdd()
    {
        $data = Request::param();
        if($data['title'] == '') {
            return ['code'=>0,'msg'=>'菜單名稱不能為空'];
        }
        if($data['controller'] == '') {
            return ['code'=>0,'msg'=>'控制器名稱不能為空'];
        }
        if($data['method'] == '') {
            return ['code'=>0,'msg'=>'方法名稱不能為空'];
        }

        $data['pid'] = 0;
        // 進行寫入操作
        $ins = SysDb::getnstance()->table('admin_menus')->insert($data);
        if(!$ins) {
            return ['code'=>0,'msg'=>'數(shù)據(jù)保存失敗,請稍后重試'];
        }
        return ['code'=>1,'msg'=>'數(shù)據(jù)保存成功'];
    }


    // 編輯操作
    public function edit()
    {
        $id = Request::param('mid');
        // 根據(jù)ID查詢數(shù)據(jù)并渲染頁面m
        $data = SysDb::getnstance()->table('admin_menus')->where(['mid'=>$id])->item();
        // 模板賦值
        $this->assign('data',$data);
        // 渲染模板
        return $this->fetch();
    }

    // 處理編輯
    public function doEdit()
    {
        $data = Request::param();
        $mid  = $data['mid'];
        unset($data['mid']);
        if($data['title'] == '') {
            return ['code'=>0,'msg'=>'菜單名稱不能為空'];
        }
        if($data['controller'] == '') {
            return ['code'=>0,'msg'=>'控制器名稱不能為空'];
        }
        if($data['method'] == '') {
            return ['code'=>0,'msg'=>'方法名稱不能為空'];
        }

        $up = SysDb::getnstance()->table('admin_menus')->where(['mid'=>$mid])->update($data);
        if(!$up) {
            return ['code'=>0,'msg'=>'數(shù)據(jù)編輯失敗'];
        }
        return ['code'=>1,'msg'=>'數(shù)據(jù)編輯成功'];
    }

    // 數(shù)據(jù)刪除
    public function doDel()
    {
        $mid = Request::param('mid');
        $del = SysDb::getnstance()->table('admin_menus')->where(['mid'=>$mid])->del();
        if(!$del) {
            return ['code'=>0,'msg'=>'數(shù)據(jù)刪除失敗'];
        }
        return ['code'=>1,'msg'=>'數(shù)據(jù)刪除成功'];
    }
}


批改老師:查無此人批改時間:2019-05-08 09:39:12
老師總結(jié):完成的不錯。后臺cms系統(tǒng),最主要的就是對數(shù)據(jù)庫增刪查改。繼續(xù)加油。

發(fā)布手記

熱門詞條