Home >PHP Framework >YII >How to run yii2.0 files on the php command line

How to run yii2.0 files on the php command line

王林
王林Original
2020-02-26 15:55:152752browse

How to run yii2.0 files on the php command line

There is a "yii" file under the yii root directory. This file is the entrance. 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 = &#39;hello world&#39;)
    {
        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 in the "controllers" directory The controller will inherit the Controller under web.

(Recommended tutorial: yii framework)

So the steps to execute the yii script in the php command line are:

1. Create a new script

Create a new controller script file in the format of "HelloController.php" under the "commands" directory.

2. Execute the script on the command line

Type "php yii project location path/yii controller name/method name" on the command line, such as "php web/yii hello/index" Or directly cd to the yii project root directory (mine is web/), and then "php yii hello/index", the command is as follows:

php web/yii refresh-tui-cur/tui-refresh

or

php yii user-test/refresh-userinfo

For more programming related content, please Pay attention to the Introduction to Programming column on the php Chinese website!

The above is the detailed content of How to run yii2.0 files on the php command line. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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