基础模板就不做过多的介绍了。
我们在yii 根目录下\console\controllers\script 新建script文件夹,创建Test控制器。
TestController.php
代码:
<?php namespace console\controllers\script; use Yii; use yii\console\Controller; use fec\helpers\CDate; use fec\helpers\CConfig; use appadmin\code\Website\models\WebsiteBaseInfo; use yii\helpers\Console; class TestController extends Controller { public function actionIndex($param1, $param2 = '') { echo "param1:" . $param1; echo "param2:" . $param2; $hello = Console::ansiFormat("Hello", [Console::FG_YELLOW]); $world = Console::ansiFormat("World", [Console::FG_GREEN]); Console::output("{$hello} {$world}"); return 0; } }
扩展阅读:
将输出字符串带颜色:https://www.imooc.com/article/23520
执行php yii script/test/index 1 2
关键字词: