ThinkPHP5.1后台搭建项目4---文章管理(上传图片、kindeditor插件)

0、说明

对后台布局做了小改,将所有的导航都放在了左侧,不影响功能的实现。

1、实现功能

(1)使用面包屑显示首页/文章管理/查看文章,且增加链接可以点击跳转
(2)增加模糊查询、多条件查询重载表格
(3)新增文章跳转新页面显示,支持上传图片,并使用富文本编辑器kindEditor
(4)编辑文章跳转新页面显示,并显示已有字段
需要新建Controller层Content.php,Model层ContentModel.php,View层index.phpedit.htmladd.html

2、数据库字段

(1)主表存储id、栏目、标题、短标题、字体颜色、封面缩略图、关键词、描述、状态、来源、用户名、创建时间、更新时间等字段。

CREATE TABLE `cms_news` (
  `news_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `catid` smallint(5) unsigned NOT NULL DEFAULT '0',
  `title` varchar(80) NOT NULL DEFAULT '',
  `small_title` varchar(30) NOT NULL DEFAULT '',
  `title_font_color` varchar(250) DEFAULT NULL COMMENT '标题颜色',
  `thumb` varchar(100) NOT NULL DEFAULT '',
  `keywords` char(40) NOT NULL DEFAULT '',
  `description` varchar(250) NOT NULL COMMENT '文章描述',
  `posids` varchar(250) NOT NULL DEFAULT '',
  `listorder` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `copyfrom` varchar(250) DEFAULT NULL COMMENT '来源',
  `username` char(20) NOT NULL,
  `create_time` int(10) unsigned NOT NULL DEFAULT '0',
  `update_time` int(10) unsigned NOT NULL DEFAULT '0',
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`news_id`),
  KEY `status` (`status`,`listorder`,`news_id`),
  KEY `listorder` (`catid`,`status`,`listorder`,`news_id`),
  KEY `catid` (`catid`,`status`,`news_id`)
) ENGINE=MyISAM AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;

(2)副表存储文章的具体内容。

CREATE TABLE `cms_news_content` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `news_id` mediumint(8) unsigned NOT NULL,
  `content` mediumtext NOT NULL,
  `create_time` int(10) unsigned NOT NULL DEFAULT '0',
  `update_time` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `news_id` (`news_id`)
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;

3、查看文章

在这里插入图片描述
表格的渲染同查看菜单,此外需要说明的点有:

(0)面包屑的实现

在这里插入图片描述
index.html

 <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;"> <!--长横线部分-->
   <legend><!--面包屑部分-->
        <a href="/index.php/admin/index/index">首页</a> /
        <a href="/index.php/admin/content/index">文章管理</a> /
        <a><cite>查看文章</cite></a>
    </legend>
</fieldset>
(1)选择栏目时,查表自动填充选项

index.html

<select name="searchbycatid" id="searchbycatid">
    <option value="">请选择栏目</option>
    {volist name="cat" id="vo"}<!--模板输出。cat是assign的变量名,vo是自定义的表示每一个item-->
    <option value="{$vo.menu_id}">{$vo.menuname}</option>
    {/volist}
</select>

Content.php

public function index()
    {
   
        //从表格获得所有的栏目
        $contentModel = new ContentModel();
        $result = $contentModel->getCatMenu();
        $this->assign('cat',$result);
        return $this->fetch();
    }

ContentModel.php

public function getCatMenu()
    {
   
        $data = [
            ['type','=',2]
        ];
        $ret = Db::table('cms_menu')->where($data)->select();
        return $ret;
    }

注意tp5.1中数组条件的查询方式,数组的格式为:

$data = [
    ['type','=',2],
    ['id','like','%12%'] //%类似于通配符
    .
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值