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. HDU 4312 Contest 2

    题目要求两点间的最大值作为距离即: 即是切比雪夫距离.而切比雪夫距离与曼哈顿距离的转换却很巧妙. 把平面坐标所有点绕原点逆向旋转45度后,所得点的曼哈顿距离之和除以√2,即是切雪比夫距离.旋转点的公式 ...

  2. Android性能优化之ListView缓存机制

    要想优化ListView首先要了解它的工作原理,列表的显示须要三个元素:ListView.Adapter.显示的数据. 这里的Adapter就是用到了适配器模式,无论传入的是什么View在ListVi ...

  3. iOS开发中的NSDateFormatter日期格式解析总结

    在工作中,常常遇到将时间解析出来转换成自己相应要求的时间格式,之前也有收集相应的转换格式,如今将自己收集的一部分了做个分享,应该比較完好了,欢迎大家继续补充 年 y 将年份 (0-9) 显示为不带前导 ...

  4. 晋IT分享成长沙龙集锦

    第一期"晋IT"分享成长沙龙于2014年7月19日圆满结束.下面是相关内容整理和第二期预告. 各位伙伴认真的介绍自己,介绍自己的业务,分析自己眼下存在的问题,大家一起探讨,真诚出谋 ...

  5. Vuejs2.0学习之二(Render函数,createElement,vm.$slots,函数化组件,模板编译,JSX)

    时隔一周多,因为一些别的事情绊住了,下面接着写.中间这段时间也有看官方文档,发现正如他所说90%的基础内容都一样,所以这里直接跳到我比较关注的东东上,要是想看看哪些不一样,可以参考这个http://v ...

  6. Apicloud自定义模块

    各种坑,折腾了两天才有点头绪.我用的是Android Studio编辑器,官网是Eclipse的视频.文档也比较蛋疼. 自定义模块的目录结构要按照下面来处理 其中res_模块名,存放res和Andro ...

  7. hdoj--1016--Prime Ring Problem(递归回溯)

    Prime Ring Problem                                                                             Time ...

  8. Install Rails on ubuntu 12.04 LTS

    There are basically there ways to install Rails development environment on your ubuntu linux system, ...

  9. [雅礼NOIP2018集训] day6

    打满暴力好像是一种挑战,已经连续几天考试最后一个小时自闭了,因为自以为打完了暴力,然而,结果往往差强人意 大概是考试的策略有些问题 T1: 我们设$g[x]$为在x时取小于等于m个物品的最大价值,下面 ...

  10. miniUI打开一个新的画面(ondestroy)

    转自:http://blog.csdn.net/u012934325/article/details/77914691 需求:开发中需求通过点击父界面一个按钮弹出一个子界面,在miniUI中我们可以这 ...