众所周知,cmd运行php单文件的命令是
E:\test>php test.php
但是自己写数据库连接或者一些其他东西就很繁琐
直接用tp就很方便
上面的命令是不适用于执行ThinkPHP内php文件的
那么在cmd怎么执行ThinkPHP内的php文件呢?
准备工作:
首先在 app > command.php 内添加如下代码
return [ 'app\index\command\Test', ];
二.在app > index 目录下创建名为 command
的文件夹, 再创建一个名为 Test.php
的文件
在 Test.php
内写入如下代码
<?php namespace app\index\command; use think\console\Command; use think\console\Input; use think\console\Output; class Test extends Command { protected function configure() { $this->setName('Test')->setDescription('Here is the remark '); } protected function execute(Input $input, Output $output) { $output->writeln("TestCommand"); // 在这里写你要执行的业务代码 } }
以上我们的准备工作就做完了~
打开小黑框:
然后我们可以打开 cmd 运行一下
注意:cmd目录切换到tp5的根目录就可以
输入: E:\test>php think Test 输出: TestCommand
-End-