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项目--个人博客(一)的更多相关文章

  1. thinkphp5项目--个人博客(八)

    thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  2. thinkphp5项目--个人博客(七)

    thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  3. thinkphp5项目--个人博客(六)

    thinkphp5项目--个人博客(六) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  4. thinkphp5项目--个人博客(五)

    thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  5. thinkphp5项目--个人博客(四)

    thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  6. thinkphp5项目--个人博客(三)

    thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  7. thinkphp5项目--个人博客(二)

    thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  8. 2015-2016-2 《Java程序设计》项目小组博客

    2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...

  9. 团队项目系列博客 —— 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号)

    团队项目系列博客 -- 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号) 标签(空格分隔): wampserver php 参考:参考文献1.慕课网.知乎.github 一.w ...

随机推荐

  1. POJ——T2352 Stars

    http://poj.org/problem?id=2352 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46592   ...

  2. Cocos2d-x使用Luajit将Lua脚本编译为bytecode,实现加密 更新

    项目要求对lua脚本进行加密,查了一下相关的资料 ,得知lua本身能够使用luac将脚本编译为字节码(bytecode)从而实现加密,试了一下,确实可行. 以下是使用原生的lua解释器编译字节码: 1 ...

  3. 仿hibernate,spring框架手动写

    近期学习了hibernate底层技术和spring 的底层技术,认为非常不错,所以想分享下,要是说的不够具体.能够去下载资源自己查看下载链接 技术的体现是在实际中的.如今大体介绍一下吧 首先介绍hib ...

  4. shareSDK的初步使用(shareSDK中微信、qq等兼容问题,以及cocoapods支持架构冲突问题的解决)

    第一次使用shareSDK来做第三方分享,可是.昨天一天都是在调试bug,一直错误不断! 先说下我的开发环境: xcode:5.1 真机调试:iPhone5s 我们都知道xcode5.1以后開始是支持 ...

  5. hdu 5335 Walk Out 搜索+贪心

    Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S ...

  6. 利用wget 抓取 网站网页 包括css背景图片

    利用wget 抓取 网站网页 包括css背景图片 wget是一款非常优秀的http/ftp下载工具,它功能强大,而且几乎所有的unix系统上都有.不过用它来dump比较现代的网站会有一个问题:不支持c ...

  7. [NOI.AC#32]sort 构造

    链接 50分做法(只有0,1) 根据归并排序的思想,假设我们现在已经把 \(l\dots mid\) 和 \(mid+1\dots r\) 排好序 只要把左边连续的1和右边连续的0翻转即可 inlin ...

  8. [jzoj NOIP2018模拟11.02]

    嗯T1忘记取模了,100到20 嗯T2忘记了那啥定理,暴力也写炸了,这题我认 嗯T3线段树合并分裂没有写炸,考场上就知道妥妥的70分.但是,分数出的时候听到有人说暴力也是70分,我???脸黑,枉我敲了 ...

  9. SpringCloud学习笔记(5)----Spring Cloud Netflix之Eureka的服务认证和集群

    1. Eureka服务认证 1. 引入依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...

  10. 集合(set)的基本操作

    集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 集合中的元素必须是不可变类型 关系测试,测试两组数据之前的交集.差集.并集等关系 常用操作 a = se ...