第一步,配置command.php文件,目录在application/command.php
<?php
return [
'app\home\command\Test',
];
第二步,建立命令类文件,新建application/home/command/Test.php
<?php
namespace app\home\command;
use app\home\model\Test as TestModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Test extends Command
{
protected function configure()
{
$this->setName('test')->setDescription('Here is the remark ');
}
protected function execute(Input $input, Output $output)
{
$testModel = new TestModel();
$res = $testModel->index();
// $output->writeln("TestCommand:".$res);
var_dump($res);
}
}
第三步,测试-命令帮助-命令行下运行(项目根目录)
php think
第四步,运行test命令
php think test