ThinkPHP5.1 cmd执行代码
                            super                        
                        
                            2020-07-31 20:16                        
                        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根目录,输入
// test = 第3步时前面单引号里面的内容
php think test

注:cmd提示: PHP 不是内部或外部命令也不是可运行的程序
0 条讨论 
                                
            