php - How to make sure the time set by crontab to execute tasks regularly?
PHPz
PHPz 2017-05-16 13:00:57
0
2
558

Take the yii2 framework as an example:
The timing configuration file console\config\params.php is configured as follows:

< /p>

Question:

1. Get the timing of the red box in the above picture from the database. When encountering
`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`
Error, how to solve it?

2. How to obtain database data in params.php of yii2? 
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