当前位置:网站首页>Yii console method call, Yii console scheduled task

Yii console method call, Yii console scheduled task

2022-07-06 01:15:00 gusijin

yii Except for building Web The rich functionality of the application ,Yii There is also a console with rich functions , They are mainly used to create the tasks of website background processing .

The structure of the console application is very similar to Yii One of the Web Applications . It consists of one or more yii\console\Controller Class composition , They are often called “ command ”. Each controller can also have one or more actions , It's like web controller .

You can run yii Script , Run it in the base directory located in the warehouse .

1、 Scheduled task writing

download Yii After the framework , You can see that there is a console Catalog , There is a complete directory structure : The configuration file 、 controller 、 Model, etc

 Insert picture description here

2、 newly build TestController.php file

<?php

namespace console\controllers;

use yii\console\Controller;

class TestController extends Controller
{
    
    /** * @var  Parameters received  */
    public $param;

    // Specify parameters for the console 
    public function options($actionID)
    {
    
        return [
            'param',
        ];
    }

    /** * @name  Script  */
    public function actionDo()
    {
    
        echo $this->param.PHP_EOL;
    }

}


3、 function php yii test/do

usage
You can use the following syntax to perform console controller actions :
php yii [ --option1=value1 --option2=value2 … argument1 argument2 … ]

 Insert picture description here

php yii test/do --param=123

Show :123

原网站

版权声明
本文为[gusijin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060114041829.html