1,编写文章添加模板
新建ArticleAddHtml.php文件:
这里用到了百度的ueditor插件
具体用法:
通过官网访问:(http://ueditor.baidu.com),进入下载页面下载PHP版本的如图所示:
下载好解压到项目根目录可以新建个umeditor文件夹,我的目录是这样的:
载入代码如下所示:(ArticleAddHtml.php)<?php
require './header.php';
header("Content-Type:text/html;charset=utf-8");
?>
后台文章管理页面
文章分类:
"><?php echo $v['name'];?>
分类管理
标题:
作者:
$(function () {
UM.getEditor('myEditor');
});
添加文章内容......
展示如下:
2,新建ArticleAdd.php文件
获取表单提交后进行数据库的添加操作
代码如下:<?php
require './init.php';
$sql='select id,name from cms_category order by sort';
$category=$db->fetchAll($sql);
if (!empty($_POST)){
//获取文章分类
$data['cid']=isset($_POST['category'])?abs(intval($_POST['category'])):0;
//获取文章标题
$data['title']=isset($_POST['title'])?trim(htmlspecialchars($_POST['title'])):'';
//获取作者
$data['author']=isset($_POST['author'])?trim(htmlspecialchars($_POST['author'])):'';
//获取文章内容
$data['content']=isset($_POST['content'])?trim($_POST['content']):'';
if(empty($data['cid'])||empty($data['title'])||empty($data['author'])){
$error[]='文章分类,标题,作者不能为空!';
}else{
$sql="insert into cms_article(title,content,author,addtime,cid)values(:title,:content,:author,now(),:cid)";
$db->data($data)->query($sql);
//跳转到首页
header("location:index.php");
}
}
require './ArticleAddHtml.php';
3,效果展示: