批改状态:合格
老师批语:
在已经安装composer下运行命令,composer create-project topthink/think thinkphp6,安装在根目录上
下载完thinkphp,在wampserver服务软件上配置,打开httpd-vhosts.conf,加上
<VirtualHost *:80>ServerName www.thinkphp6.ioServerAlias www.thinkphp6.ioDocumentRoot "${INSTALL_DIR}/www/thinkphp6/public"<Directory "${INSTALL_DIR}/www/thinkphp6/public/">Options +Indexes +Includes +FollowSymLinks +MultiViewsAllowOverride AllRequire local</Directory></VirtualHost>
打开电脑hosts文件,(C:\Windows\System32\drivers\etc\hosts),通过管理员的权限运行cmd,
配置完,就可以在浏览器上输入www.thinkphp6.io/index.php.访问
<?php// +----------------------------------------------------------------------// | 应用设置// +----------------------------------------------------------------------return [// 应用地址'app_host' => env('app.host', ''),// 应用的命名空间'app_namespace' => '',// 是否启用路由'with_route' => true,// 默认应用'default_app' => 'index',// 默认时区'default_timezone' => 'Asia/Shanghai',// 应用映射(自动多应用模式有效)'app_map' => [],// 域名绑定(自动多应用模式有效)'domain_bind' => [],// 禁止URL访问的应用列表(自动多应用模式有效)'deny_app_list' => [],// 异常页面的模板文件'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',// 错误显示信息,非调试模式有效'error_message' => '页面错误!请稍后再试~',// 显示错误信息 默认是false'show_error_msg' => true,];
<?phpreturn [// 默认使用的数据库连接配置'default' => env('database.driver', 'mysql'),// 自定义时间查询规则'time_query_rule' => [],// 自动写入时间戳字段// true为自动识别类型 false关闭// 字符串则明确指定时间字段类型 支持 int timestamp datetime date'auto_timestamp' => true,// 时间字段取出后的默认时间格式'datetime_format' => 'Y-m-d H:i:s',// 时间字段配置 配置格式:create_time,update_time'datetime_field' => '',// 数据库连接配置信息'connections' => ['mysql' => [// 数据库类型'type' => env('database.type', 'mysql'),// 服务器地址'hostname' => env('database.hostname', '127.0.0.1'),// 数据库名'database' => env('database.database', 'thinkphp'),// 用户名'username' => env('database.username', 'user'),// 密码'password' => env('database.password', '123456'),// 端口'hostport' => env('database.hostport', '3308'),// 数据库连接参数'params' => [],// 数据库编码默认采用utf8'charset' => env('database.charset', 'utf8'),// 数据库表前缀'prefix' => env('database.prefix', 'think_'),// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)'deploy' => 0,// 数据库读写是否分离 主从式有效'rw_separate' => false,// 读写分离后 主服务器数量'master_num' => 1,// 指定从服务器序号'slave_no' => '',// 是否严格检查字段是否存在'fields_strict' => true,// 是否需要断线重连'break_reconnect' => false,// 监听SQL'trigger_sql' => env('app_debug', true),// 开启字段缓存'fields_cache' => false,],// 更多的数据库配置信息'mysql_two' => [// 数据库类型'type' => env('database.type', 'mysql'),// 服务器地址'hostname' => env('database.hostname', '127.0.0.1'),// 数据库名'database' => env('database.database', ''),// 用户名'username' => env('database.username', 'root'),// 密码'password' => env('database.password', ''),// 端口'hostport' => env('database.hostport', '3306'),// 数据库连接参数'params' => [],// 数据库编码默认采用utf8'charset' => env('database.charset', 'utf8'),// 数据库表前缀'prefix' => env('database.prefix', ''),// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)'deploy' => 0,// 数据库读写是否分离 主从式有效'rw_separate' => false,// 读写分离后 主服务器数量'master_num' => 1,// 指定从服务器序号'slave_no' => '',// 是否严格检查字段是否存在'fields_strict' => true,// 是否需要断线重连'break_reconnect' => false,// 监听SQL'trigger_sql' => env('app_debug', true),// 开启字段缓存'fields_cache' => false,],],];
<?phpnamespace app\controller;use app\BaseController;use think\facade\Db;use think\facade\Request;class Index extends BaseController{public function index(){// return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';// $result = Db::table('think_user')->where('uid','>',1)->select();// $result = Db::table('think_user')->where('uid', 10)->find();// $result = Db::table('think_user')->where('uid', 10)->findOrFail();// $result = Db::table('think_user')->where('uid', 10)->findOrEmpty();$table = Db::table('think_user');// $result = $table->where('status',0)->selectOrFail()->toArray();// $result = $table->where('uid',2)->value('nickname');// $result = $table->where('status',1)->column('nickname,phone');// $result = Db::table('think_user')->where('status',1)->column('*','uid');// $result = Db::table('think_user')->where('uid','>',7)->chunk(2,function($users){// foreach($users as $key =>$value){// $value['status'] = 0;// }// });// $cursor = Db::table('think_user')->where('status',1)->cursor();// foreach($cursor as $key => $value){// echo $value['nickname'];// }// $data = ['nickname'=>'Rom','phone'=>'122345678912'];// $result = Db::table('think_user')->save($data);// $result = Db::table('think_user')->insertGetId($data);// $result = Db::table('think_user')->insert($data);// $data = [// ['nickname'=>'Rom','phone'=>'122345678912'],// ['nickname'=>'Wom','phone'=>'122345678912'],// ['nickname'=>'Fom','phone'=>'122345678912'],// ['uid'=>12,'nickname'=>'Bom','phone'=>'122345678912'],// ];// $result = Db::table('think_user')// ->limit(2)// ->insertAll($data);// $result = Db::table('think_user')// ->where('uid',23)// ->useSoftDelete('delete_time',time())// ->fetchSql(true)// ->delete();// $result = $table->select();// $result->isEmpty();// print_r($result);// $result = Db::table('think_user')->select();//// print_r($result);}}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号