yii框架学习 6-1 console 命令行

1、命令带参数

2、定时任务脚本例子 

<?php

namespace consolecontrollers;
use commonmodelsPostware;

/**
 * 定时关闭订单任务脚本
 * Class SemihCloseOrderController
 * @package consolecontrollers
 */
class SemihCloseOrderController extends yiiconsoleController
{
    public function actionIndex(){
        $postware = Postware::find()->select(["id"])->where(['<', 'created_at', date("Y-m-d H:i:s", time()-30*60)])->andWhere(['in','state', [0,1]])->asArray()->all();
        $ids = array_column($postware, 'id');
        $res = Postware::updateAll(['state'=>12],['in','id', $ids]);
        file_put_contents(__DIR__."/../../../runtimes/console/logs/SemihCloseOrder.log", date("Y-m-d H:i:s", time())."--close postware_id:".var_export($ids,true).PHP_EOL, FILE_APPEND);

    }
}

3、控制台命令的选项

原文地址:https://www.cnblogs.com/gaogaoxingxing/p/12794106.html