fry404006308/personalBlog: personalBlog
https://github.com/fry404006308/personalBlogjavascript
1 /* 2 Navicat MySQL Data Transfer 3 4 Source Server : localhost_3306 5 Source Server Version : 50553 6 Source Host : localhost:3306 7 Source Database : personalblog 8 9 Target Server Type : MYSQL 10 Target Server Version : 50553 11 File Encoding : 65001 12 13 Date: 2018-04-09 04:27:03 14 */ 15 16 DROP database IF EXISTS `personalBlog`; 17 create database personalBlog character set utf8 collate utf8_general_ci; 18 use personalBlog; 19 20 SET FOREIGN_KEY_CHECKS=0; 21 22 -- ---------------------------- 23 -- Table structure for tp_admin 24 -- ---------------------------- 25 DROP TABLE IF EXISTS `tp_admin`; 26 CREATE TABLE `tp_admin` ( 27 `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 28 `username` varchar(255) DEFAULT NULL COMMENT '管理員名稱', 29 `password` varchar(255) DEFAULT NULL COMMENT '管理員密碼', 30 PRIMARY KEY (`id`) 31 ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 32 33 -- ---------------------------- 34 -- Records of tp_admin 35 -- ---------------------------- 36 37 -- ---------------------------- 38 -- Table structure for tp_article 39 -- ---------------------------- 40 DROP TABLE IF EXISTS `tp_article`; 41 CREATE TABLE `tp_article` ( 42 `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '文章id', 43 `title` varchar(255) DEFAULT NULL COMMENT '文章標題', 44 `author` varchar(255) DEFAULT NULL COMMENT '文章做者', 45 `desc` varchar(255) DEFAULT NULL COMMENT '文章簡介', 46 `keywords` varchar(255) DEFAULT NULL COMMENT '文章的關鍵詞', 47 `content` text COMMENT '文章內容', 48 `pic` varchar(255) DEFAULT NULL COMMENT '文章縮略圖,是一個地址', 49 `click` int(10) unsigned zerofill DEFAULT NULL COMMENT '點擊數', 50 `state` int(10) unsigned zerofill DEFAULT NULL COMMENT '文章狀態 0:不推薦 1:推薦', 51 `time` int(11) DEFAULT NULL COMMENT '文章發佈時間,時間戳', 52 `cateid` int(11) DEFAULT NULL COMMENT '文章所屬的欄目', 53 PRIMARY KEY (`id`) 54 ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 55 56 -- ---------------------------- 57 -- Records of tp_article 58 -- ---------------------------- 59 60 -- ---------------------------- 61 -- Table structure for tp_cate 62 -- ---------------------------- 63 DROP TABLE IF EXISTS `tp_cate`; 64 CREATE TABLE `tp_cate` ( 65 `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '欄目id', 66 `catename` varchar(255) DEFAULT NULL COMMENT '欄目名稱', 67 PRIMARY KEY (`id`) 68 ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 69 70 -- ---------------------------- 71 -- Records of tp_cate 72 -- ---------------------------- 73 74 -- ---------------------------- 75 -- Table structure for tp_tags 76 -- ---------------------------- 77 DROP TABLE IF EXISTS `tp_tags`; 78 CREATE TABLE `tp_tags` ( 79 `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '標籤id', 80 `tagname` varchar(255) DEFAULT NULL COMMENT '標籤名', 81 PRIMARY KEY (`id`) 82 ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 83 84 -- ---------------------------- 85 -- Records of tp_tags 86 -- ----------------------------
拿後臺舉例php
上面部分和左邊的公共部分被放在了公共文件夾中html
引用以下:java
top部分jquery
1 <!-- 頭部 --> 2 {include file="common/top"} 3 <!-- /頭部 -->
left部分git
1 <!-- Page Sidebar --> 2 {include file="common/left"} 3 <!-- /Page Sidebar -->
1 public function add() 2 { 3 //判斷是否爲post方法提交 4 if(request()->isPost()){ 5 // dump(input('post.')); 6 // 若是提交消息成功,咱們就添加消息到數據庫 7 8 // // 服務器端對數據進行驗證 9 // $validate = new Validate([ 10 // 'username' => 'require|max:25', 11 // 'password' => 'require|min:32' 12 // ]); 13 // 一、接收傳遞過來的數據 14 15 $data=[ 16 'username'=>input('username'), 17 'password'=>md5(input('password')), 18 ]; 19 20 $validate = Loader::validate('Admin'); 21 if(!$validate->scene('add')->check($data)){ 22 $this->error($validate->getError()); die; 23 } 24 25 // if (!$validate->check($data)) { 26 // dump($validate->getError()); 27 // die; 28 // } 29 30 // if添加成功,就指向success頁面 31 if(Db::name('admin')->insert($data)){ 32 return $this->success('添加管理員成功!!','lst'); 33 }else{ 34 return $this->error('添加管理員失敗!!'); 35 } 36 return; 37 } 38 return view(); 39 }
1 use think\Validate; 2 3 public function add() 4 { 5 //判斷是否爲post方法提交 6 if(request()->isPost()){ 7 // dump(input('post.')); 8 // 若是提交消息成功,咱們就添加消息到數據庫 9 10 // // 服務器端對數據進行驗證 11 // $validate = new Validate([ 12 // 'username' => 'require|max:25', 13 // 'password' => 'require|min:32' 14 // ]); 15 // 一、接收傳遞過來的數據 16 17 $data=[ 18 'username'=>input('username'), 19 'password'=>md5(input('password')), 20 ]; 21 22 $validate = Loader::validate('Admin'); 23 if(!$validate->scene('add')->check($data)){ 24 $this->error($validate->getError()); die; 25 } 26 27 // if (!$validate->check($data)) { 28 // dump($validate->getError()); 29 // die; 30 // } 31 32 // if添加成功,就指向success頁面 33 if(Db::name('admin')->insert($data)){ 34 return $this->success('添加管理員成功!!','lst'); 35 }else{ 36 return $this->error('添加管理員失敗!!'); 37 } 38 return; 39 } 40 return view(); 41 }
1 public function lst() 2 { 3 // 分頁輸出列表 每頁顯示3條數據 4 $list = AdminModel::paginate(3); 5 $this->assign('list',$list); 6 return view('list'); 7 }
1 <body> 2 <!-- 頭部 --> 3 {include file="common/top"} 4 <!-- /頭部 --> 5 6 <div class="main-container container-fluid"> 7 <div class="page-container"> 8 9 <!-- Page Sidebar --> 10 {include file="common/left"} 11 <!-- /Page Sidebar --> 12 13 <!-- Page Content --> 14 <div class="page-content"> 15 <!-- Page Breadcrumb --> 16 <div class="page-breadcrumbs"> 17 <ul class="breadcrumb"> 18 <li> 19 <a href="{:url('index/index')}">系統</a> 20 </li> 21 <li class="active">用戶管理</li> 22 </ul> 23 </div> 24 <!-- /Page Breadcrumb --> 25 26 <!-- Page Body --> 27 <div class="page-body"> 28 29 <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 30 </button> 31 <div class="row"> 32 <div class="col-lg-12 col-sm-12 col-xs-12"> 33 <div class="widget"> 34 <div class="widget-body"> 35 <div class="flip-scroll"> 36 <table class="table table-bordered table-hover"> 37 <thead class=""> 38 <tr> 39 <th class="text-center" width="10%">ID</th> 40 <th class="text-center">用戶名稱</th> 41 <th class="text-center" width="20%">操做</th> 42 </tr> 43 </thead> 44 <tbody> 45 {volist name="list" id="value"} 46 <tr> 47 <td align="center">{$value.id}</td> 48 <td align="center">{$value.username}</td> 49 <td align="center"> 50 <a href="/admin/user/edit/id/6.html" class="btn btn-primary btn-sm shiny"> 51 <i class="fa fa-edit"></i> 編輯 52 </a> 53 54 {if condition="$value['id'] neq 1"} 55 <a href="#" onClick="warning('確實要刪除嗎', '{:url('admin/del',array('id'=>$value['id']))}')" class="btn btn-danger btn-sm shiny"> 56 <i class="fa fa-trash-o"></i> 刪除 57 </a> 58 {/if} 59 60 </td> 61 </tr> 62 {/volist} 63 64 </tbody> 65 </table> 66 <div class="text-right" style="margin-top: 10px"> 67 {$list->render()} 68 </div> 69 70 </div> 71 <div> 72 </div> 73 </div> 74 </div> 75 </div> 76 </div> 77 78 </div> 79 <!-- /Page Body --> 80 </div> 81 <!-- /Page Content --> 82 </div> 83 </div> 84 85 <!--Basic Scripts--> 86 <script src="__PUBLIC__/style/jquery_002.js"></script> 87 <script src="__PUBLIC__/style/bootstrap.js"></script> 88 <script src="__PUBLIC__/style/jquery.js"></script> 89 <!--Beyond Scripts--> 90 <script src="__PUBLIC__/style/beyond.js"></script> 91 92 93 94 </body>
分頁之因此代碼特別少是由於配置裏面是有配置好了的github
1 //分頁配置 2 'paginate' => [ 3 'type' => 'bootstrap', 4 'var_page' => 'page', 5 'list_rows' => 15, 6 ],
1 <?php 2 namespace app\admin\model; 3 4 use think\Model; 5 class Admin extends Model 6 { 7 8 }
控制器中sql
1 use app\admin\model\Admin as AdminModel; 2 3 4 public function lst() 5 { 6 // 分頁輸出列表 每頁顯示3條數據 7 $list = AdminModel::paginate(3); 8 $this->assign('list',$list); 9 return view('list'); 10 }