官方号令行应用开辟文档见此
英文原文: How to implement cron in Yii 2
In advance template there is already a file yii. And there is no need to run it as php, it is Linux script.
在高等模版中的 yii 文件,它是一个 Linux 脚本,不须要应用PHP来运行。
Create a controller in console/controllers
在 console/controllers 文件夹下创建一个把握器
I have created as TestController.php
我创建了一个名为 TestController.php 的文件
<?php
namespace console\controllers;
use yii\console\Controller;
/**
* Test controller
*/
class TestController extends Controller {
public function actionIndex() {
echo "cron service runnning";
}
public function actionMail($to) {
echo "Sending mail to " . $to;
}
}
This controller should be use the console controller name space
这个把握器该当应用号令行把握器的定名空间
use yii\console\Controller;
run it as
应用如式格式运行
I have test it on windows by running
我在 windows 下应用如式格式运行
D:\xampp\htdocs\yii2>d:\xampp\php\php yii test
cron service runnning
D:\xampp\htdocs\yii2>
</pre><pre name="code" class="plain">yii test/mail [--to="hemctest@gmail.com"]
in windows for test it run as
在 windows 中测试如下
D:\xampp\htdocs\yii2>d:\xampp\php\php yii test/mail [--to="hemctest@gmail.com"]
Sending mail to [--to=hemctest@gmail.com]
官方号令行应用开辟文档见此
英文原文: How to implement cron in Yii 2