0
点赞
收藏
分享

微信扫一扫

tp 自定义指令

创建自定义指令操作步骤:

第一步:运行指令

php think make:command Auto auto

       运行后即可看到在 app\command 目录生成的 Auto.php

 修改里面的代码:行指令

<?php
declare (strict_types = 1);
 
namespace app\command;
 
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
 
class Auto extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('statistics')
            ->setDescription('the auto command');
    }
 
    protected function execute(Input $input, Output $output)
    {
        echo 1;
    }
 
}

第二步:修改 config/console.php 文件

<?php
    return [
       'commands' => [
           'auto' => 'app\command\Auto',
        ]
    ];

第三步:测试

php think auto

结果:输出了1

举报

相关推荐

0 条评论