thinkphp CLI command line to run PHP code ____php

Source: Internet
Author: User

These days in the process of doing a project, just need to use the CLI in thinkphp to run a controller in the method, in the official manual to find, found, do not know how to use:



Confused, has been Baidu TP5 how to use the CLI implementation of the method under the controller, and even I want to run the PHP file directly, I need to execute the class file to instantiate the class and Invoke methods, and then in the cmd command to enter the directory of the file

It's just that if you execute a single PHP script, that's fine, but to run the files in the TP5 framework, various classes and usage methods are not found or undefined.

Then I thought, since I can't find the way to execute the controller, I'm going to say that the code executes directly in the command file Execute method,


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 result you want,

Then in the cmd command line, enter the project directory, enter


You can run the PHP code and output the results. Finally, the question now is how the thinkphp CLI command line operates in 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.