The resources in Yii are files related to Web pages, CSS files, javascript files, pictures, videos, and so on, and resources are placed in the Web accessible directory and are directly invoked by the Web server.
Sometimes there are functions that need to be done to plan tasks, so yii can be executed with PHP commands. The yii2.0 is supported by the PHP command line and is operated as follows:
There is a "yii" file (not "Yii.bat") underneath the Yii root directory, and this file is the portal. Then the "commands" directory will default to have a "hellocontroller.php" controller file, this is a demo. Open the controller file, the source code is as follows (delete part of the note):
<?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 echoed.
* * Public
function Actionindex ($message = ' Hello World ')
{
echo $message. "\ n";
}
}
As you can see from the above, the Controller under the console are inherited while the command line is running, and the controllers in the general "controllers" directory inherit the controller under the Web.
So the steps to perform a yii script on the PHP command line are:
1. Create a new script
Under the "Commands" directory, create a new controller script file in the format "hellocontroller.php".
2. Execute script at command line
At the command line, "/yii the path to the PHP Yii project, the controller name/method name", such as "PHP E:/wwwroot/yii2/yii Hello/index", as shown in the following figure.
It's important to Note that PHP must set the environment variable before it can be used. to find out if PHP has added environment variables, use the "php-v" command to view them.
Three kinds of controller classes in Yii
Base\controller.php this is the base class for the following two
Console\controller.php This is the console controller.
Web\controller.php This is the Web controller
The above content is a small series through an example to explain yii2.0 in the PHP command line to run the steps, I hope you like.