前言
从慕课网上搞了一套ThinkPHP整站开发从前端到后台的视频教程,好好系统的学习一下MVC模式下的正规开发流程,做一下学习过程中的开发笔记.
1.系统概述
这套教程视频中使用了ThinkPHP框架,但是有点老了,用的还是3.2.3版本的,不过思路很重要,等全做好了可以考虑再用最新的5.x版本重构一遍.教程中要开发实现的是一套CMS信息管理类的后台+前台信息展示,前端用到了Bootstrap以及周边的一些js控件,系统效果先看一下:
前端首页
后台界面:
2.数据库准备
准备以下数据表:
CREATE TABLE `cms_admin` (`admin_id` int(6) unsigned NOT NULL AUTO_INCREMENT,`username` varchar(20) NOT NULL DEFAULT '',`password` varchar(32) NOT NULL,`lastloginip` varchar(15) DEFAULT NULL,`lastlogintime` int(10) DEFAULT NULL,`email` varchar(40) DEFAULT NULL,`realname` varchar(50) DEFAULT NULL,`status` tinyint(1) DEFAULT NULL,PRIMARY KEY (`admin_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;CREATE TABLE `cms_menu` (`menu_id` int(6) NOT NULL AUTO_INCREMENT,`name` varchar(40) DEFAULT NULL,`parentid` int(6) DEFAULT NULL,`m` varchar(20) DEFAULT NULL,`c` varchar(20) DEFAULT NULL,`f` varchar(20) DEFAULT NULL,`listorder` int(6) DEFAULT NULL,`status` tinyint(1) DEFAULT NULL,`type` tinyint(1) DEFAULT NULL,PRIMARY KEY (`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;CREATE TABLE `cms_news` (`news_id` int(8) NOT NULL AUTO_INCREMENT,`catid` int(5) DEFAULT NULL,`title` varchar(80) DEFAULT NULL,`small_title` varchar(30) DEFAULT NULL,`title_font_color` varchar(255) DEFAULT NULL,`thumb` varchar(255) DEFAULT NULL,`keywords` varchar(255) DEFAULT NULL,`description` varchar(255) DEFAULT NULL,`listorder` tinyint(3) DEFAULT NULL,`status` tinyint(1) DEFAULT NULL,`copyfrom` varchar(255) DEFAULT NULL,`username` varchar(255) DEFAULT NULL,`create_time` int(10) DEFAULT NULL,`update_time` int(10) DEFAULT NULL,`count` int(10) DEFAULT NULL,PRIMARY KEY (`news_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;CREATE TABLE `cms_news_content` (`id` int(8) NOT NULL AUTO_INCREMENT,`news_id` int(8) DEFAULT NULL,`content` text,`create_time` int(10) DEFAULT NULL,`update_time` int(10) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;CREATE TABLE `cms_position` (`id` int(5) NOT NULL AUTO_INCREMENT,`name` varchar(255) DEFAULT NULL,`status` tinyint(1) DEFAULT NULL,`description` varchar(255) DEFAULT NULL,`create_time` int(10) DEFAULT NULL,`update_time` int(10) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;CREATE TABLE `cms_position_content` (`id` int(5) NOT NULL AUTO_INCREMENT,`position_id` int(5) DEFAULT NULL,`title` varchar(255) DEFAULT NULL,`thumb` varchar(255) DEFAULT NULL,`url` varchar(255) DEFAULT NULL,`news_id` int(8) DEFAULT NULL,`listorder` tinyint(3) DEFAULT NULL,`status` tinyint(1) DEFAULT NULL,`create_time` int(10) DEFAULT NULL,`update_time` int(10) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
3.准备ThinkPHP框架
官网下载ThinkPHP 3.2.3 Core
http://www.thinkphp.cn/down/611.html
解压后得到基本的框架结构,第一次从浏览器打开后会自动生成Common,Home,Runtime等相关文件结构
4.配置ThinkPHP配置参数
4.1配置Application/Common/Conf/config.php
<?php
return array(//'配置项'=>'配置值' 'LOAD_EXT_CONFIG' => 'db', //加载外部配置文件db.php,该文件存放位置与config.php同级别'MD5_PRE' => 'lian', //自定义的配置参数,后面进行MD5加密的时候用到的后缀
);
4.2新建Applicaion/Common/Conf/db.php配置数据库连接信息
<?php
return array(//'配置项'=>'配置值' 'DB_TYPE' => 'mysql','DB_HOST' => '127.0.0.1','DB_USER' => 'root','DB_PWD' => '','DB_PORT' => 3306,'DB_NAME' => 'muke','DB_CHARSET' => 'utf8','DB_PREFIX' => 'cms_',
);