thinkphp6笔记
1、创建多应用模式
安装thinkphp6,比如新建demo项目
composer create-project topthink/think demo
安装多应用模式扩展
composer require topthink/think-multi-app
新建应用admin
php think build admin
命令行出现succeed! 说明成功!再删除app目录下的controller
测试:
php think run
http:/127.0.0.1/admin/index/index,如果80端口被占用,就是: http://127.0.0.1:8000/admin/index/index
2、常用命令
php think build admin //生成应用 php think make:controller Blog //生成控制器 php think make:controller index@Blog //生成index应用的控制器
php think make:model index@Blog //生成模型
php think clear //清除缓存
3、request方法:
use think\Request; //方法注入调用请求 use think\facade\Request; //静态调用请求 request(); //助手函数获取请求 $request->param('name'); $request->get('name'); $request->post('name'); $request->name;// 获取请求参数 input('name'); input('get.name'); input('post.name') // 助手函数,获取请求参数 $request->param(); //获取当前所有请求 $request->has('id','get'); $request->has('name','post'); input('?post.name'); input('?get.name'); //检查参数是否设置 $request->url(); // 获取完整URL地址 不带域名 $request->url(true); // 获取完整URL地址 包含域名 $request->controller(); // 获取当前控制器 $request->action(); // 获取当前操作 app('http')->getName(); // 获取当前应用 $request->method(); //获取请求类型 $request->isPost(); $request->isGet(); $request->isAjax(); $request->isMobile(); //判断请求类型 redirect('/index/list'); //重定向
redirect((string) url('hello',['name' => 'think'])); //重定向,使用url生成地址
技巧方法:
1、tp5、tp6中,input的变量修饰符:
input('post.ids/a'); //强制转换为数组类型
input('get.id/d'); //强制转换为整形类型
input('post.name/s'); //强制转换为字符串类型,其他:/f 浮点类型、/b 布尔类型
用法:input('get.id','默认值','过滤函数')
2、thinkphp6默认只能支持PHP原生模板,如果需要使用thinkTemplate模板引擎(thinkphp5.1带的),需要安装think-view扩展。参考
3、TP5叫钩子,TP6改叫事件,使用方法:参考
浙公网安备 33010602011771号