thinkphp6自定义命令行命令不生效-[InvalidArgumentException] Command “test“ is not defined.

按照官方的写法不生效,做个笔记。

  • 将命令放在app\AppService.php文件中绑定(没有这个文件则创建)
commands([
            'test' => \app\index\command\Test::class
        ]);
    }
}
  • 对应的Test.php文件
setName('test')->setDescription('Here is the remark ');
    }

    protected function execute(Input $input, Output $output)
    {
        $output->writeln("TestCommand:");
    }
}
  • 然后执行php think 
W:\www\regaing>php think
version 6.0.6

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -V, --version         Display this console version
  -q, --quiet           Do not output any message
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  build             Build App Dirs
  clear             Clear runtime file
  help              Displays help for a command
  list              Lists commands
  run               PHP Built-in Server for ThinkPHP
  test              Here is the remark                     //这个就是刚才绑定的命令名称
  version           show thinkphp framework version
  • 然后执行php think test 
W:\www\regaing>php think test
TestCommand:

W:\www\regaing>

thinkphp6自定义命令行命令不生效-[InvalidArgumentException] Command "test" is not defined.-凌雲-记得博客网

你可能感兴趣的:(php,TP6)