Home > PHP Framework > ThinkPHP > body text

thinkPHP cli command line to run PHP code

藏色散人
Release: 2020-09-30 14:31:39
forward
3541 people have browsed it

The tutorial column of thinkphp below will introduce to you how to run PHP code on the thinkPHP cli command line. I hope it will be helpful to friends in need!

thinkPHP cli command line to run PHP code

In the process of working on projects these days, I just need to use cli in thinkPHP to run a method in a controller. I looked it up in the official manual. After I found it, I didn’t know how to use it at all:



## I was confused and kept asking how to use the cli to execute Baidu tp5 The method under the controller, even I want to run the PHP file directly, I instantiate the class in the class file that needs to be executed and call the method, and then enter the directory where the file is located in the cmd command

It’s just that if you execute a single PHP script, there is no problem with this approach, but if you want to run files in the tp5 framework, various classes and usage methods will not be found or defined.

Later I thought, since I couldn’t find the method under the execution controller, then I would put the code in the execute method of the command file and execute it directly,


Then create a new command folder in the index module, and create a new Test.php file in the folder. The code is as follows:



In the execute method, place the PHP code that needs to be run. You can output the results you want in the left back.

Then enter the project directory on the cmd command line and enter


You can run the PHP code and output the results! Finally solved it, now the problem I encounter is how to operate the thinkPHP cli command line in Linux!

The above is the detailed content of thinkPHP cli command line to run PHP code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template