1.在application/common目录下 新建command文件夹
2.创建文件test.php<?php
namespace app\common\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
//use think\Db;
class test extends Command
{
protected function configure()
{
$this->setName('test')
->setDescription('test tp5 cli mode');
}
protected function execute(Input $input, Output $output)
{
ini_set('max_execution_time', 0);
echo "Hello, world!".PHP_EOL;
$output->writeln("hello test!");
}
}
3.在application/command.php中写入以下代码return [
'test' => 'app\common\command\test',
];
4.打开cmd,进入ThinkPHP根目录,输入php think test

本文详细介绍了如何在ThinkPHP框架中创建并运行自定义命令行工具,包括新建command文件夹、编写test.php文件、配置和执行命令。通过这个过程,读者可以学习如何利用ThinkPHP的CLI模式进行快速开发和脚本操作。
6447

被折叠的 条评论
为什么被折叠?



