文件名称:模型定义-az-303_222q
文件大小:6.83MB
文件格式:PDF
更新时间:2024-07-03 04:47:53
thinkphp5
(1)模型定义 模型定义 为了更好的理解,我们首先在数据库创建一个 think_user 表如下: CREATE TABLE IF NOT EXISTS `think_user`( `id` int(8) unsigned NOT NULL AUTO_INCREMENT, `nickname` varchar(50) NOT NULL COMMENT '昵称', `email` varchar(255) NULL DEFAULT NULL COMMENT '邮箱', `birthday` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '生日', `status` tinyint(2) NOT NULL DEFAULT '0' COMMENT '状态', `create_time` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '注册时间', `update_time` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新时间', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; 数据库配置文件定义如下: return [ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 'database' => 'demo', // 数据库用户名 'username' => 'root', // 数据库密码 'password' => '', // 数据库连接端口 'hostport' => '', // 数据库连接参数 'params' => [], // 数据库编码默认采用utf8 'charset' => 'utf8', // 数据库表前缀 'prefix' => 'think_', // 数据库调试模式 'debug' => true, ]; 并添加路由定义( application/route.php )如下: return [ // 全局变量规则定义 '__pattern__' => [ 'id' => '\d+', ], 'user/index' => 'index/user/index', 'user/create' => 'index/user/create', 'user/add' => 'index/user/add', 'user/add_list' => 'index/user/addList', 'user/update/:id' => 'index/user/update', (1)模型定义 - 70 -本文档使用 看云 构建