19
2023
06

tp5.1 cli、脚本、command文档

api\application\command.php 添加

return [
    'test' => 'app\common\command\Xxx',
];
G:\phpstudy_pro\WWW\lzl\api>php think image
<?php
 
namespace app\index\command;
 
 
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
 
class CronImage extends Command
{
    protected function configure()
    {
        $this->addArgument('type', Argument::REQUIRED); //必传参数
        //$this->addArgument('type', Argument::OPTIONAL);//可选参数
        $this->setName('CronImage')->setDescription("设置图片表测试数据");//setName与文件名称保持一致 setDEscription则是说明
    }
 
    /**
     * 业务逻辑
     * @param Input $input
     * @param Output $output
     * @return int|void|null
     */
    protected function execute(Input $input, Output $output)
    {
        $output->writeln('type value');
        $type = $input->getArgument('type');
        switch($type)
        {
            case 1:
                echo 1;
                break;
            case 2:
                echo '2-';
                break;
        }
    }
}

执行:php think CornImage 1

« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。