1.配置command.php文件,目录在application/command.php

格式
return [
// 'app\index\command\UserLoinLog',
'app\index\command\Test' //指向 index项目下的command文件夹
];
2.创建 执行类文件
namespace app\index\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Test extends Command
{
protected function configure()
{
//这个文件定义了一个叫test的命令,备注为Here is the remark,执行命令php think 能查看到备注信息
$this->setName('test')->setDescription('这是一个测试 ');
}
/**
* php think test 调用的方法
*
* @param Input $input
* @param Output $output
* @return int|null|void
*/
protected function execute(Input $input, Output $output)
{
$output->writeln("TestCommand:");
}
}
3. 测试-命令帮助-命令行下运行
在tp 项目路径下 php think

出现test代表命令行 注册成功
4 运行test命令

execute 方法被成功调用
用sheel脚本
https://www.cnblogs.com/seizemiss/p/9467558.html
4 log注意换行
echo '\n' 是字符
echo "\n" 是换行
网友评论