TP5.1使用命令执行一个方法
看到有其他的教程中说要配置command.php文件,我本次未配置
如果有遇到无法运行到程序的,可以按以下来配置
<?php
return [
'app\index\command\Transform',
];
然后就是在application 创建一个command文件夹,在里面创建命令类文件,名字自己取,我这里是Transform.php
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Transform extends Command
{
protected function configure(){
$this->setName('Trans')->setDescription('数据转换描述内容');
}
protected function execute(Input $input, Output $output)
{
$Transform = new \app\index\controller\Transform();
$re = $Transform->trans();
if($re == 'ok'){
$output->write('success');
}else{
$output->write('error');
}
}
}
在项目输入 php think Trans 运行,则可以看到运行结果