yii2 console commands

1. HelloController.php


<?php
namespace console\controllers;

use Yii;
use yii\console\Controller;

class HelloController extends  Controller{
    public $sex;

    public function options( $actionID ){
        return ['sex'];
    }

    public function actionIndex($name){
        echo "Hello ". $name;
        echo "<br>";
        echo $this->sex;
        return 0;
    }


}


2. Run yii.bat hello/index --sex=male meng under cmd

       hello/index: controller route

       --sex=male: controller public properties

       meng: parameters of the index action

3. Running result:




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324606150&siteId=291194637