ThinkPHP提供自定義命令功能,參考手冊(cè) 。
如何自定義TP6的命令,參考thinkphp6 command(自定義指令)。
1. 建立app/test/command/Hello.php。
<?php
declare (strict_types = 1);
namespace app\test\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
class Hello extends Command
{
protected function configure()
{
// 指令配置
$this->setName('hello')
->setDescription('the hello command');
}
protected function execute(Input $input, Output $output)
{
// 指令輸出
$output->writeln('Hello ' . date('Y-m-d H:i:s'));
}
}
2. 配置config\console.php。
<?php
return [
'commands' => [
'app\test\command\Hello',
],
];
3. 測(cè)試命令執(zhí)行結(jié)果。

浙公網(wǎng)安備 33010602011771號(hào)