tp5下的command使用

昨天接触到开发任务是使用到了tp5的command,上网找了一下相关的资料,蛮简单的。。。

第一步、先创建一个类,继承Command,此处我在application\sapi\Command\文件夹下创建getData.php文件

<?php
namespace app\sapi\Command;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class getData extends Command {
    protected function configure()
    {
        $this->setName('getData')//定义命令的名字
        ->setDescription('获取线索数据');//定义命令的描述
    }
    protected function execute(Input $input, Output $output)
    {
        //具体执行的代码逻辑
       $this->getData();
    }
}
其中 configure和execute方法是默认要有的,大体可以理解为configure是用来注册执行命令,execute是执行具体的代码逻辑。

第二步、注册command,路径是在application\command.php 

<?php
return [
    'app\sapi\Command\getData',
];

第三步、确认注册的执行命令
cmd中输入php think,如果注册成功的话,就可以看到具体的执行命令

 第四步、执行命令

可以在宝塔上添加计划任务,执行shell脚本

su -c "/www/server/php/56/bin/php /www/wwwroot/xxxxxxx.com(项目域名路径)/think getData(任务名称)"  -s /bin/sh www

我用的是PHPstorm编辑器,可以使用底部的命令来执行,cmd也可以

 command的使用很广泛,具体的使用场景根据自己的需要来定

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值