文章目录
0、说明
对后台布局做了小改,将所有的导航都放在了左侧,不影响功能的实现。
1、实现功能
(1)使用面包屑显示首页/文章管理/查看文章
,且增加链接可以点击跳转
(2)增加模糊查询、多条件查询重载表格
(3)新增文章跳转新页面显示,支持上传图片,并使用富文本编辑器kindEditor
(4)编辑文章跳转新页面显示,并显示已有字段
需要新建Controller层Content.php
,Model层ContentModel.php
,View层index.php
、edit.html
、add.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%'] //%类似于通配符 .