十年专注于品牌网站建设 十余年专注于网站建设_小程序开发_APP开发,低调、敢创新、有情怀!
南昌百恒网络微信公众号 扫一扫关注
小程序
tel-icon全国服务热线:400-680-9298,0791-88117053
扫一扫关注百恒网络微信公众号
扫一扫打开百恒网络微信小程序

百恒网络

南昌百恒网络

thinkphp6 命令大全及使用方法

wangs 2024-02-19 196

安装tp6:composer create-project topthink/think demo

启用多应用模式:composer require topthink/think-multi-app

启动内置服务:php think run定制端口:php think run -H tp.com -p 80

查看当前版本:php think version

自动生成应用(需启用多应用模式):php think build demo

创建类库文件(多应用):php think make:controller index@Demo

创建类库文件(单应用):php think make:controller Demo

安装视图驱动:composer require topthink/think-view



安装稳定版:

composer create-project topthink/think tp 

更新稳定版:

composer update topthink/framework 

安装开发板:

composer create-project topthink/think=6.0.x-dev tp 

开启多应用扩展命令:

composer require topthink/think-multi-app 

模板引擎驱动命令:

composer require topthink/think-view 

生成一个服务类:

php think make:service  FileSystemService 

生成一个事件:

php think make:event UserLogin 

生成一个监听类:

php think make:listener UserLogin 

生成一个订阅者类:

php think make:subscribe User 

生成一个中间件:

php think make:middleware Check 

路由反解URL:

php think optimize:route 

创建一个资源控制类:

Route::resource(\\\\\\\\\\\\\\\'blog\\\\\\\\\\\\\\\', \\\\\\\\\\\\\\\'Blog\\\\\\\\\\\\\\\')->vars([\\\\\\\\\\\\\\\'blog\\\\\\\\\\\\\\\' => \\\\\\\\\\\\\\\'blog_id\\\\\\\\\\\\\\\']); 

资源控制器:生成index应用的Blog

php think make:controller index@Blog 

或者使用完整的命名空间生成

php think make:controller app\\\\\\\\\\\\\\\\index\\\\\\\\\\\\\\\\controller\\\\\\\\\\\\\\\\Blog 

南昌小程序开发公司百恒网络开发工程师提醒大家如果只是用于接口开发,可以使用

php think make:controller index@Blog --api 

然后你只需要为资源控制器注册一个资源路由:

Route::resource(\\\\\\\\\\\\\\\'blog\\\\\\\\\\\\\\\', \\\\\\\\\\\\\\\'Blog\\\\\\\\\\\\\\\'); 

Trace调试功能就是ThinkPHP提供给开发人员的一个用于开发调试的辅助工具。可以实时显示当前页面或者请求的请求信息、运行情况、SQL执行、错误信息和调试信息等,并支持自定义显示,并且支持没有页面输出的操作调试。最新版本页面Trace功能已经不再内置在核心,但默认安装的时候会自动安装topthink/think-trace扩展,所以你可以在项目里面直接使用。
如果部署到服务器的话,你可以通过下面方式安装

composer install --no-dev

下面介绍下系统自带的几个命令,包括:


指令 描述
build 自动生成应用目录和文件
help 帮助
list 指令列表
clear 清除缓存指令
run 启动PHP内置服务器
version 查看当前框架版本号
make:controller 创建控制器类
make:model 创建模型类
make:command 创建指令类文件
make:validate 创建验证器类
make:middleware 创建中间件类
make:event 创建事件类
make:listener 创建事件监听器类
make:subscribe 创建事件订阅者类
make:service 创建系统服务类
optimize:autoload 生成类库映射文件
optimize:config 生成配置缓存文件
optimize:schema 生成数据表字段缓存文件
optimize:facade 生成Facade注释
route:build 生成注解路由
route:list 查看路由定义
service:discover 自动注册扩展包的系统服务
vendor:publish 自动生成扩展的配置文件

更多的指令可以自己扩展。
命令行切换到应用根目录后,输入:

>php think run 

如果启动成功,会输出下面信息,并显示web目录位置。

ThinkPHP Development server is started On You can exit with `CTRL-C`
Document root is: D:\\\\\\\\\\\\\\\\WWW\\\\\\\\\\\\\\\\tp6/public 

如果不需要保留空目录,可以使用

php think clear --dir 

清除日志目录

php think clear --log 

清除日志目录并删除空目录

php think clear --log --dir 

清除数据缓存目录

php think clear --cache 

清除数据缓存目录并删除空目录

php think clear --cache --dir 

如果需要清除某个指定目录下面的文件,可以使用:

php think clear --path d:\\\\\\\\\\\\\\\\www\\\\\\\\\\\\\\\\tp\\\\\\\\\\\\\\\\runtime\\\\\\\\\\\\\\\\log\\\\\\\\\\\\\\\\ 

安装

Workerman_154" style="box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:#4183C4;position:absolute;margin-top:-10px;">Workerman

首先通过 composer 安装

composer require topthink/think-worker 

WorkermanHttpServer_159" style="box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:#4183C4;position:absolute;margin-top:-10px;">使用Workerman作为HttpServer

在命令行启动服务端

php think worker 

然后就可以通过浏览器直接访问当前应用

http://localhost:2346 

linux下面可以支持下面指令

php think worker [start|stop|reload|restart|status] 

workerman的参数可以在应用配置目录下的worker.php里面配置。

由于onWorkerStart运行的时候没有HTTP_HOST,因此最好在应用配置文件中设置app_host

SocketServer_174" style="box-sizing:inherit;-webkit-tap-highlight-color:transparent;text-size-adjust:none;-webkit-font-smoothing:antialiased;background-color:transparent;color:#4183C4;position:absolute;margin-top:-10px;">SocketServer

在命令行启动服务端(需要2.0.5+版本)

php think worker:server 

默认会在0.0.0.0:2345开启一个websocket服务。
如果需要自定义参数,可以在config/worker_server.php中进行配置,包括:

配置参数 描述
protocol 协议
host 监听地址
port 监听端口
socket 完整的socket地址

###swoole扩展,然后使用

composer require topthink/think-swoole

百恒网络,专业专注于南昌小程序开发、南昌APP开发,南昌网站建设,为用户提供高品质网络产品和优质服务是我们始终的追求,欢迎来电咨询洽谈。
400-680-9298,0791-88117053
扫一扫关注百恒网络微信公众号
扫一扫打开百恒网络小程序

欢迎您的光顾,我们将竭诚为您服务×

售前咨询 售前咨询
 
售前咨询 售前咨询
 
售前咨询 售前咨询
 
售前咨询 售前咨询
 
售前咨询 售前咨询
 
售后服务 售后服务
 
售后服务 售后服务
 
备案专线 备案专线
 
×