thinkphp CLI command to run PHP code instance

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.