Yii resources are files related to Web pages. They can be CSS files, JavaScript files, images or videos. Resources are placed in accessible Web directories and directly called by Web servers. This article explains how to run yii2.0 in the php command line through an example. If you are interested in yii2.0php, learn about the resources in Yii as files related to Web pages. They can be CSS files, javaScript files, images, videos, and other resources are stored in accessible Web directories and directly called by Web servers.
Sometimes some functions need to be scheduled, so yii needs to be executed using php commands. Yii2.0 supports the php Command Line Operation as follows:
There is a "yii" file (not "yii. bat") under the yii root directory. This file is the portal. The "commands" directory contains a "HelloController. php" Controller file by default. This is a demo. Open the Controller file. The source code is as follows (some comments are deleted ):
<?phpnamespace 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"; }}
It can be seen from the above that the Controller under the console will be inherited when running the command line; while the Controller in the "controllers" directory will inherit the Controller under the web.
Therefore, the steps for executing the yii script in the php Command Line are as follows:
1. Create a script
Create a controller script file in the "commands" directory in the "HelloController. php" format.
2. Execute the script on the command line.
Type "php yii project path/yii controller name/method name" in the command line, for example, "php E:/wwwroot/yii2/yii hello/index", as shown in.
It should be noted that php must set the environment variable before it can be used. To see if php has added environment variables, run the "php-v" command.
Three controller classes in Yii
Base \ Controller. php: The following two base classes
Console \ Controller. php this is the console Controller
Web \ Controller. php: web Controller
The above section describes how to run yii2.0 in the php command line through an example.