yii2.0 supports php command line operation.
The operation method is as follows:
There is a "yii" file under the yii root directory (not "yii.bat"), this file is the entry. Then there will be a "HelloController.php" controller file by default in the "commands" directory, which is a demo. Open this controller file, the source code is as follows (some comments are deleted):
<?php namespace app\commands;use yii\console\Controller;class HelloController extends Controller { /** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex($message = ‘hello world‘) { echo $message . "\n"; } }
As can be seen from the above, when running on the command line, the Controller under the console will be inherited; and generally the Controller in the "controllers" directory The controller will inherit the Controller under web.
The steps to execute the yii script in the php command line are:
1. Create a new script
Follow the "HelloController" command under the "commands" directory Create a new controller script file in the format of .php".
2. Execute the script on the command line
Type "php yii project location path/yii controller name/method name" on the command line, for example "php E:/wwwroot/yii2/ yii hello/index”
As shown below:
or as shown below
It should be noted that: PHP must set environment variables before it can be used in this way. If you want to know whether php has been added to the environment variable, please use the "php -v" command to check.
PHP Chinese website has a large number of free Yii introductory tutorials, everyone is welcome to learn!
The above is the detailed content of How to execute cmd command on e disk yii. For more information, please follow other related articles on the PHP Chinese website!