thinkphp5项目--个人博客(一)
thinkphp5项目--个人博客(一)
项目地址
fry404006308/personalBlog: personalBlog
https://github.com/fry404006308/personalBlog
一、数据表创建




/*
Navicat MySQL Data Transfer Source Server : localhost_3306
Source Server Version : 50553
Source Host : localhost:3306
Source Database : personalblog Target Server Type : MYSQL
Target Server Version : 50553
File Encoding : 65001 Date: 2018-04-09 04:27:03
*/ DROP database IF EXISTS `personalBlog`;
create database personalBlog character set utf8 collate utf8_general_ci;
use personalBlog; SET FOREIGN_KEY_CHECKS=0; -- ----------------------------
-- Table structure for tp_admin
-- ----------------------------
DROP TABLE IF EXISTS `tp_admin`;
CREATE TABLE `tp_admin` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL COMMENT '管理员名称',
`password` varchar(255) DEFAULT NULL COMMENT '管理员密码',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of tp_admin
-- ---------------------------- -- ----------------------------
-- Table structure for tp_article
-- ----------------------------
DROP TABLE IF EXISTS `tp_article`;
CREATE TABLE `tp_article` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '文章id',
`title` varchar(255) DEFAULT NULL COMMENT '文章标题',
`author` varchar(255) DEFAULT NULL COMMENT '文章作者',
`desc` varchar(255) DEFAULT NULL COMMENT '文章简介',
`keywords` varchar(255) DEFAULT NULL COMMENT '文章的关键词',
`content` text COMMENT '文章内容',
`pic` varchar(255) DEFAULT NULL COMMENT '文章缩略图,是一个地址',
`click` int(10) unsigned zerofill DEFAULT NULL COMMENT '点击数',
`state` int(10) unsigned zerofill DEFAULT NULL COMMENT '文章状态 0:不推荐 1:推荐',
`time` int(11) DEFAULT NULL COMMENT '文章发布时间,时间戳',
`cateid` int(11) DEFAULT NULL COMMENT '文章所属的栏目',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of tp_article
-- ---------------------------- -- ----------------------------
-- Table structure for tp_cate
-- ----------------------------
DROP TABLE IF EXISTS `tp_cate`;
CREATE TABLE `tp_cate` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '栏目id',
`catename` varchar(255) DEFAULT NULL COMMENT '栏目名称',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of tp_cate
-- ---------------------------- -- ----------------------------
-- Table structure for tp_tags
-- ----------------------------
DROP TABLE IF EXISTS `tp_tags`;
CREATE TABLE `tp_tags` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '标签id',
`tagname` varchar(255) DEFAULT NULL COMMENT '标签名',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of tp_tags
-- ----------------------------
sql创建数据库及表完整代码
二、前后台模板分离
拿后台举例

上面部分和左边的公共部分被放在了公共文件夹中

引用如下:
top部分
<!-- 头部 -->
{include file="common/top"}
<!-- /头部 -->
left部分
<!-- Page Sidebar -->
{include file="common/left"}
<!-- /Page Sidebar -->
三、管理员添加

public function add()
{
//判断是否为post方法提交
if(request()->isPost()){
// dump(input('post.'));
// 如果提交消息成功,我们就添加消息到数据库 // // 服务器端对数据进行验证
// $validate = new Validate([
// 'username' => 'require|max:25',
// 'password' => 'require|min:32'
// ]);
// 1、接收传递过来的数据 $data=[
'username'=>input('username'),
'password'=>md5(input('password')),
]; $validate = Loader::validate('Admin');
if(!$validate->scene('add')->check($data)){
$this->error($validate->getError()); die;
} // if (!$validate->check($data)) {
// dump($validate->getError());
// die;
// } // if添加成功,就指向success页面
if(Db::name('admin')->insert($data)){
return $this->success('添加管理员成功!!','lst');
}else{
return $this->error('添加管理员失败!!');
}
return;
}
return view();
}
四、数据验证及验证场景详解

use think\Validate;
public function add()
{
//判断是否为post方法提交
if(request()->isPost()){
// dump(input('post.'));
// 如果提交消息成功,我们就添加消息到数据库
// // 服务器端对数据进行验证
// $validate = new Validate([
// 'username' => 'require|max:25',
// 'password' => 'require|min:32'
// ]);
// 1、接收传递过来的数据
$data=[
'username'=>input('username'),
'password'=>md5(input('password')),
];
$validate = Loader::validate('Admin');
if(!$validate->scene('add')->check($data)){
$this->error($validate->getError()); die;
}
// if (!$validate->check($data)) {
// dump($validate->getError());
// die;
// }
// if添加成功,就指向success页面
if(Db::name('admin')->insert($data)){
return $this->success('添加管理员成功!!','lst');
}else{
return $this->error('添加管理员失败!!');
}
return;
}
return view();
}
五、管理员列表及分页

public function lst()
{
// 分页输出列表 每页显示3条数据
$list = AdminModel::paginate(3);
$this->assign('list',$list);
return view('list');
}
<body>
<!-- 头部 -->
{include file="common/top"}
<!-- /头部 --> <div class="main-container container-fluid">
<div class="page-container"> <!-- Page Sidebar -->
{include file="common/left"}
<!-- /Page Sidebar --> <!-- Page Content -->
<div class="page-content">
<!-- Page Breadcrumb -->
<div class="page-breadcrumbs">
<ul class="breadcrumb">
<li>
<a href="{:url('index/index')}">系统</a>
</li>
<li class="active">用户管理</li>
</ul>
</div>
<!-- /Page Breadcrumb --> <!-- Page Body -->
<div class="page-body"> <button type="button" tooltip="添加用户" class="btn btn-sm btn-azure btn-addon" onClick="javascript:window.location.href = '{:url('admin/add')}'"> <i class="fa fa-plus"></i> Add
</button>
<div class="row">
<div class="col-lg-12 col-sm-12 col-xs-12">
<div class="widget">
<div class="widget-body">
<div class="flip-scroll">
<table class="table table-bordered table-hover">
<thead class="">
<tr>
<th class="text-center" width="10%">ID</th>
<th class="text-center">用户名称</th>
<th class="text-center" width="20%">操作</th>
</tr>
</thead>
<tbody>
{volist name="list" id="value"}
<tr>
<td align="center">{$value.id}</td>
<td align="center">{$value.username}</td>
<td align="center">
<a href="/admin/user/edit/id/6.html" class="btn btn-primary btn-sm shiny">
<i class="fa fa-edit"></i> 编辑
</a> {if condition="$value['id'] neq 1"}
<a href="#" onClick="warning('确实要删除吗', '{:url('admin/del',array('id'=>$value['id']))}')" class="btn btn-danger btn-sm shiny">
<i class="fa fa-trash-o"></i> 删除
</a>
{/if} </td>
</tr>
{/volist} </tbody>
</table>
<div class="text-right" style="margin-top: 10px">
{$list->render()}
</div> </div>
<div>
</div>
</div>
</div>
</div>
</div> </div>
<!-- /Page Body -->
</div>
<!-- /Page Content -->
</div>
</div> <!--Basic Scripts-->
<script src="__PUBLIC__/style/jquery_002.js"></script>
<script src="__PUBLIC__/style/bootstrap.js"></script>
<script src="__PUBLIC__/style/jquery.js"></script>
<!--Beyond Scripts-->
<script src="__PUBLIC__/style/beyond.js"></script> </body>
分页之所以代码特别少是因为配置里面是有配置好了的
//分页配置
'paginate' => [
'type' => 'bootstrap',
'var_page' => 'page',
'list_rows' => 15,
],
六、模型

<?php
namespace app\admin\model; use think\Model;
class Admin extends Model
{ }
控制器中
use app\admin\model\Admin as AdminModel;
public function lst()
{
// 分页输出列表 每页显示3条数据
$list = AdminModel::paginate(3);
$this->assign('list',$list);
return view('list');
}
thinkphp5项目--个人博客(一)的更多相关文章
- thinkphp5项目--个人博客(八)
thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(七)
thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(六)
thinkphp5项目--个人博客(六) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(五)
thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(四)
thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(三)
thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(二)
thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- 2015-2016-2 《Java程序设计》项目小组博客
2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...
- 团队项目系列博客 —— 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号)
团队项目系列博客 -- 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号) 标签(空格分隔): wampserver php 参考:参考文献1.慕课网.知乎.github 一.w ...
随机推荐
- android开发面试题
找了将近两个星期的工作,面试了5家公司,罗列一下笔试或者面试时的问题,祝大家好运 1,handler机制 答:handler执行机制:1).在主线程中创建handler 2).子线程中借助主线程的ha ...
- unity3d 延迟运行脚本语句
在Unity3D中.有yield语句它负责延迟操作,yield return WaitForSeconds(3.0); //等待 3 秒 查看unity3d脚本手冊,使用方法须要在对应的格式. 以下代 ...
- React-Native系列Android——Native与Javascript通信原理(一)
React-Native最核心的是Native与Javascript之间的通信,并且是双向通信.Native层到Javascript层,Javascript层到Native层.虽说是两个方向,但实现上 ...
- JS冒泡事件 与 事件捕获
JS冒泡事件 与 事件捕获 案例 <!DOCTYPE html> <html> <head> <title>冒泡事件</title> < ...
- Effective Java(一)—— 创建和销毁对象
在客户端(调用端)获取自身实例的方法: 公有的构造器: 类的静态工厂方法: 1. 使用静态工厂方法代替构造器 Boolean 是对基本类型 boolean 的包装类: public final cla ...
- MySQL日期数据类型和时间类型使用总结
转自: http://blog.chinaunix.net/space.php?uid=11327712&do=blog&id=32416 MySQL 日期类型:日期格式.所占存储空间 ...
- java 获取线程id
如何获取正在运行的线程的ID? 解决方法 下面的示例演示如何使用getThreadId() 方法一个正在运行线程的ID. public class Main extends Object implem ...
- seq去除重复数据
DELETE FROM temp_fjh_2 a WHERE a.rowid!=(SELECT MAX(b.rowid) FROM temp_fjh_2 b WHERE a.a=b.a); 表名和列名 ...
- scrapy框架学习
一.初窥Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. 其最初是为了 页面抓取 (更确切来说, 网 ...
- vue项目测试和打包发布
在线测试:npm run dev 发布打包:npm run build 打包后,代码文件在dist文件夹下面,可以正式发布了,复制到其它web服务器下面,在浏览器用http访问.