Home > PHP Framework > YII > body text

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

王林
Release: 2020-02-26 15:55:15
Original
2655 people have browsed it

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";
    }
}
Copy after login

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
Copy after login

or

php yii user-test/refresh-userinfo
Copy after login

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!

Related labels:
php
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!