ThinkPHP建立自定義命令列
阿新 • • 發佈:2019-02-20
第一步,配置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