tp5.1调用php文件,ThinkPHP5.1 cmd执行代码

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

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

1596167470126539.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值