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改叫事件,使用方法:参考

 

posted on   飞哥100  阅读(384)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2017-03-21 npm命令点滴记录
2017-03-21 webpack点滴记录

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示