虚拟点餐系统(7)项目初始化
安装TP5.1框架
TP5.1环境要求
PHP >= 5.6.0
PDO PHP Extension
MBstring PHP Extension
Composer安装
composer create-project topthink/think=5.1.* restaurant
创建数据库
数据库名称 restaurant 字符编码 utf8
数据表
CREATE TABLE `tp_category` ( `id` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `cat_name` varchar(90) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '分类名称', `create_time` int(11) null default 0 comment '添加维护字段', `update_time` int(11) null default 0 comment '更新维护字段', `delete_time` int(11) null default 0 comment '删除维护字段', PRIMARY KEY (`id`) USING BTREE ) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '商品分类表';
CREATE TABLE `tp_goods` ( `id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT, `cat_id` smallint(5) UNSIGNED NOT NULL DEFAULT 0 COMMENT '所属分类id', `goods_name` varchar(120) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '商品名称', `price` decimal(10, 0) UNSIGNED NOT NULL DEFAULT 0 COMMENT '价格', `goods_brief` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '摘要', `goods_img` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '高清图', `sort_order` smallint(4) UNSIGNED NOT NULL DEFAULT 100 COMMENT '排序号', `is_hot` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否热销', `is_on_sale` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否上架', `create_time` int(11) null default 0 comment '添加维护字段', `update_time` int(11) null default 0 comment '更新维护字段', `delete_time` int(11) null default 0 comment '删除维护字段', PRIMARY KEY (`id`) USING BTREE, INDEX `cat_id`(`cat_id`) USING BTREE, INDEX `sort_order`(`sort_order`) USING BTREE ) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '商品基本表';
CREATE TABLE `tp_order` ( `id` int(11) NOT NULL AUTO_INCREMENT, `order_id` varchar(80) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '订单号', `total_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '总价格', `member_id` int(11) NULL DEFAULT NULL COMMENT '会员ID', `pay_status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0-未付款 ,1-已付款', `ali_order_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '交易号', `number` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '数量', `create_time` int(11) NULL DEFAULT 0 COMMENT '添加维护字段', `update_time` int(11) NULL DEFAULT 0 COMMENT '更新维护字段', `delete_time` int(11) null default 0 COMMENT '删除维护字段', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE `tp_order_attr` ( `id` int(11) NOT NULL AUTO_INCREMENT, `order_id` varchar(80) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '订单号', `goods_id` int(11) NOT NULL COMMENT '商品ID', `price` decimal(10, 2) NULL DEFAULT NULL COMMENT '价格', `number` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '数量', `create_time` int(11) NULL DEFAULT 0 COMMENT '添加维护字段', `update_time` int(11) NULL DEFAULT 0 COMMENT '更新维护字段', `delete_time` int(11) null default 0 COMMENT '删除维护字段', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_general_ci;
初始设置
// config/app.php // 应用调试模式 'app_debug' => true, // 是否强制使用路由 'url_route_must' => true, // 路由是否完全匹配 'route_complete_match' => true,
// config/database.php // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 'database' => 'restaurant', // 用户名 'username' => '自定义', // 密码 'password' => '自定义', // 端口 'hostport' => '3306', // 数据库表前缀 'prefix' => '自定义', // 数据集返回类型 'resultset_type' => 'collection', // 部分数据需要toArray()
隐藏入口文件
// public/.htaccess RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
初始化路由
// route/route.php <?php Route::get('/', function () { return 'hello,ThinkPHP5!'; });
// 在没有匹配到所有的路由规则后会跳转到miss路由 Route::miss(function(){ return '非法请求'; });
浙公网安备 33010602011771号