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. [POJ3233]Matrix Power Series 分治+矩阵

    本文为博主原创文章,欢迎转载,请注明出处 www.cnblogs.com/yangyaojia [POJ3233]Matrix Power Series 分治+矩阵 题目大意 A为n×n(n<= ...

  2. hdu1276(士兵队列训练问题) java集合水过

    点击打开链接 有人说这题属于栈或者队列,个人认为说集合应该比較准确点. Problem Description 某部队进行新兵队列训练,将新兵从一開始按顺序依次编号.并排成一行横队,训练的规则例如以下 ...

  3. kentico api

    http://devnet.kentico.com/docs/10_0/api/html/R_Project_Kentico_API.htm ScriptHelper.RegisterClientSc ...

  4. PFILE和SPFILE介绍

    一.PFILE Pfile(Parameter File,参数文件)是基于文本格式的参数文件,含有数据库的配置参数. 1.PFILE - initSID.ora(默认PFILE名称),位置在$ORAC ...

  5. Kettle学习系列之数据仓库、数据整合、ETL、ELT和EII之间的区别?

    不多说,直接上干货! 在数据仓库领域里,的一个重要概念就是数据整合(data intergration).数据整合它就是把不同数据库中的数据整合到一起,对外提供统一的数据视图. 数据整合最典型的案例就 ...

  6. Android View 上下左右四种间距的设置方法

    RecyclerView控件大家肯定不陌生,已经应用有一段时间了,最近在项目中写一个GridLayout样式的RecyclerView时需要设置,item之间左右的间距,下面是我总结的一个设置间距的方 ...

  7. @RequestMapping[转]

    转自 http://www.cnblogs.com/qq78292959/p/3760560.html#undefined 引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST. ...

  8. hadoop 编译自己的jar包并运行

    我修从网上找了份java代码 我为了让它在hadoop下跑起来居然花了两个多小时... 首先最好不要在java代码中设置package...使用default package即可... 然后在java ...

  9. Windows上快速编译caffe CPU版本

    windows上快速安装配置Caffe的 cpu_only环境. 一:安装环境: 1.windows10: 2.Visual Studio2013: 3.Caffe版本:http://github.c ...

  10. 一、数组---数组中的K-diff数对※※※※※

    给定一个整数数组和一个整数 k, 你需要在数组里找到不同的 k-diff 数对.这里将 k-diff 数对定义为一个整数对 (i, j), 其中 i 和 j 都是数组中的数字,且两数之差的绝对值是 k ...