php - crontab 定时执行任务所定的时间怎么做成活的?
PHPz
PHPz 2017-05-16 13:00:57
0
2
537

拿yii2框架来讲:
定时配置文件console\config\params.php配置如下:

问题:

1、把上图红框部分的定时从数据库获取,遇到
`PHP Fatal error:  Call to a member function getDb() on null in /home/wwwroot/default/ceshi/vendor/yiisoft/yii2/db/ActiveRecord.php on line 133`
错误,怎么解决?

2、yii2 的params.php如何获取数据库数据?
PHPz
PHPz

学习是最好的投资!

reply all(2)
習慣沉默

Write it in the form of an anonymous function

return [
    'adminEmail'=>'admin@xx.com',
    'cronJobs'=>[
        'contact/send'=>[
                //code
        ],
        'contact/hsend'=>[
            'cron'=>function(){
                //todo 获取数据库中的定时配置(可以在外面写个自定义函数获取)
                $_cron2 = you_function();
                return $_cron2;
            }
        ]
    ]
]



<?php

$data = [
    'cronJobs'=>[
        'send'=>[
            //code
        ],
        'hsend'=>[
            'cron'=>function(){
                return '888888';
            }
        ]
    ]
];
echo $data['cronJobs']['hsend']['cron'](); //这么写
phpcn_u1582

(Thank you for the invitation) Sorry, I don’t know much about yii2. But for the TP approach, I will dynamically generate the time configuration, read the database setting time in the public controller, and generate the configuration parameters. In this way, you can use it happily (you can refer to it, I hope it will be helpful to you).

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!