Thinkphp command使用

本文介绍了如何在ThinkPHP框架中使用command功能。首先,配置application/command.php,然后创建命令类文件如Test.php。接着,在CMD中进入项目目录执行'php think Test'来运行命令。此外,还讨论了带参数的使用方式,例如通过docker执行带有参数的ThinkPHP command。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步,配置command.php文件,目录在application/command.php

<?php
return [
    'app\home\command\Test',
];

第二步,建立命令类文件,新建application/home/command/Test.php

<?php
namespace app\home\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Test extends Command
{
    protected function configure()
    {
        $this->setName('test')->setDescription('任务描述');
    }
    protected function execute(Input $input, Output $output)
    {
    	$output->writeln('请求时间:'.date('Y-m-d H:i:s'));
    	//处理过程………………
        $output->writeln("TestCommand:");
    }
}

第三步,打开cmd,进入到项目目录D:\phpstudy_pro\WWW\newweb
执行 php think Test

补充 thinkphp command
带参数
docker exec -it -u www-data cli /usr/local/bin/php /data/website/latest/abthink Test add_order
接收参数

    protected function configure()
    {
        $this->setName('Test')->setDescription('数据上报');
        $this->addArgument("action", Argument::REQUIRED, "The name of the class");
    }
    
    protected function execute(Input $input, Output $output)
    {
        $output->writeln('执行前---' . date("Y-m-d H:i:s", time()) . '<br>');
        $type = $input->getArgument("action");
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值