These days in the process of doing the project, just need to use the CLI in the thinkphp to run a controller in the method, find in the official manual, found, do not know how to use, this article mainly share with you thinkphp CLI command running PHP code instance, hope to help everyone.
Confused, has been Baidu TP5 how to use the CLI to execute the method under the controller, even I want to run the PHP file directly, I need to execute the class file to instantiate the class and invoke the method, and then in the cmd command to enter the directory where the file
Only, if you execute a single PHP script, this is not a problem, but to run the files in the TP5 framework, the various classes and methods of use cannot be found or undefined.
And then I thought, since I can't find the execution controller, I'm going to put the code in the command file Execute method directly,
Then create a new command folder in the index module and create a new test.php file in the folder with the following code:
The Execute method places the PHP code that needs to be run, and the left can output the results you want,
Then on the cmd command line, enter the project directory, enter
You can run the PHP code and output the results! Finally, the problem is that the thinkphp CLI command line is operating on Linux!