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 cron service command創建計劃任務服務命令Create a controller in console/controllers
在 console/controllers 文件夾下創建一個控制器
I have created as TestController.php
我創建了一個名為 TestController.php 的文件
<?php
namespaceconsole/controllers;useyii/console/Controller;/***Testcontroller*/classTestControllerextendsController{publicfunctionactionIndex(){echo"cronservicerunnning";}publicfunctionactionMail($to){echo"SendinGmailto".$to;}}This controller should be use the console controller name space
這個控制器應當使用命令行控制器的命名空間
use yii/console/Controller;
run it as
使用如下方式運行
yii test
I have test it on windows by running
我在 windows 下使用如下方式運行
D:/xampp/htdocs/yii2>d:/xampp/php/phpyiitest
cronservicerunnningD:/xampp/htdocs/yii2>How to pass params如何傳遞參數yii test/mail [--to="hemctest@gmail.com"]
in windows for test it run as
在 windows 中測試如下
D:/xampp/htdocs/yii2>d:/xampp/php/phpyiitest/mail[--to="hemctest@gmail.com"]
Sendingmailto[--to=hemctest@gmail.com]官方命令行應用開發文檔見此
英文原文:How to implement cron in Yii 2
本文由專注于成都網站建設的信易網絡發布,更多關于yii的信息請關注信易網絡隨后的發布,信易網絡的官網http://www.ir58.com
新聞熱點
疑難解答