这里写目录标题TP5自定义命令行
创建自定义命令行
第一步,配置command.php文件,目录在application/command.php
<?php
return ['app\index\controller\Test'];
第二步,建立命令类文件,新建application\index\controller\Test.php
<?php
namespace app\home\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Test extends Command
{
protected function configure(){
$this->setName('Test')->setDescription("计划任务 Test");
}
protected function execute(Input $input, Output $output){
$output->writeln('Date Crontab job start...');
/*** 这里写计划任务列表集 START ***/
$this->test();
/*** 这里写计划任务列表集 END ***/
$output->writeln('Date Crontab job end...');
}
private function test(){
echo "testfhjfjjg\r\n";
}
}
configure()方法里面设置自定义的命令行命令,setName()方法是命令;setDescription()方法是该命令的描述。
execute()方法执行命令操作($this->其他的操作)