Classification authority and list management

Classification table design

CREATE TABLE "zh_article_category" (
  "id" int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
  "user_id" int(11) DEFAULT NULL COMMENT '用户主键',
  "name" varchar(30) DEFAULT NULL COMMENT '栏目名称',
  "sort" int(11) DEFAULT NULL COMMENT '栏目排序',
  "status" int(11) DEFAULT '1' COMMENT '状态 1启用 0禁用',
  "create_time" int(11) DEFAULT NULL COMMENT '创建时间',
  "update_time" int(11) DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY ("id")
);

article_category model code

<?php
namespace app\admin\common\model;
use think\Model;

class Cate extends Model
{
    protected $pk = 'id';
    protected $table = 'zh_article_category';
}

cate.php controller code

<?php
namespace app\admin\controller;

use app\admin\common\controller\Base;
use app\admin\common\model\Cate as CateModel;
use think\facade\Request;
use think\facade\Session;

class Cate extends Base
{
    //分类管理的首页
    public function index()
    {
        //检查用户是否登录
        $this->isLogin();
        //登录成功后就直接跳转到分类管理界面
        return $this->redirect('cateList');
    }
    //分类列表
    public function cateList()
    {
        //1.检查用户是否登录
        $this->isLogin();
        //2.获取所有的分类
        $cateList = CateModel::all();
        //3.设置模板变量
        $this->view->assign('title','分类管理');
        $this->view->assign('empty','<span style="color:red">没有分类</span>');
        $this->view->assign('cateList',$cateList);

        //渲染分类显示模板
        return $this->view->fetch('catelist');
    }
}

front-end code catelist.html

{layout name="public:layout" /}
<h4 class="text-center text-success">分类管理</h4>
<table class="table table-default table-hover text-center">
    <tr>
        <td>ID</td>
        <td>栏目名称</td>
        <td>排序</td>
        <td>状态</td>
        <td>创建时间</td>
        <td colspan="2">操作</td>
    </tr>
    {volist name="cateList" id="cate" empty="$empty"}
    <tr>
        <td>{$cate.id}</td>
        <td>{$cate.name}</td>
        <td>{$cate.sort}</td>
        {eq name="$cate.status" value="1"}
        <td style="color: forestgreen">显示</td>
        {else /}
        <td style="color: gray">隐藏</td>
        {/eq}
        <td>{$cate.create_time}</td>
        <td><a href="{:url('cate/cateEdit',['id'=>$cate.id])}">编辑</a></td>
        <td><a href="javascript:;" onclick="dele();return false">删除</a></td>
    </tr>
    {/volist}
</table>
<script>
    function dele(){
        if(confirm('您是真的要删除吗?') == true) {
//            这里需要禁用a链接方法一:href="javascript: ;"  或者方法二:return false
            window.location.href = "{:url('cate/doDelete',['id'=>$cate.id])}";
        }
    }
</script>

Show results
Here Insert Picture Description

Published 100 original articles · won praise 0 · Views 3768

Guess you like

Origin blog.csdn.net/weixin_39218464/article/details/104377767