在Yii2.0中实现计划任务(cron)
以下由我们在信易网络公司开发项目的时候终结出的一些经验
Create console application
创建命令行应用
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
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;
How to run it
如何运行
run it as
使用如下方式运行
yii test
I have test it on windows by running
我在 windows 下使用如下方式运行
D:\xampp\htdocs\yii2>d:\xampp\php\php yii test
cron service runnningD:\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\php yii test/mail [--to="hemctest@gmail.com"]
Sending mail to [--to=hemctest@gmail.com]官方命令行应用开发文档见此
英文原文: How to implement cron in Yii 2
本文由专注于成都网站建设的信易网络发布,更多关于yii的信息请关注信易网络随后的发布,信易网络的官网http://www.ir58.com
在Yii2.0中实现计划任务(cron)的更多相关文章
- yii2.0中url重写实现方法
在yii框架里有前台和后台页面,举例前台url重写. 控制器与路由 控制器以Controller作为后缀,继承自yii\web\Controller; 动作以action作为前缀,public访问修饰 ...
- yii2.0 中的队列
a yii2 extension to make simple to use queue. yii2-queue让队列的使用在yii2中变得更轻松,她为各种队列组件的使用提供了一个标准的接口,您只需要 ...
- YII2.0中实现高级注册
如何在不修改逻辑代码的情况下完美解决以上三个问题?看了下面的教程,一目了然! 以高级版2.0.6为例,打开/frontend/models/SignupForm.php class SignupFor ...
- Yii2.0中场景的使用小记
熟悉Yii框架的人都知道,灵活的使用场景可以达到事半功倍的效果! 比如普通的数据的新增.修改,新增需要验证其中两个字段,而修改只需要验证其中一个字段:还有种情况,也是我们现在用到的,同一张表(同一个m ...
- yii2.0中Rbac 怎么添加超加管理员
最笨的是定义常量.具体怎么做?看下面: //定义在控制器声明上面define('BEST_PHPER',serialize(array('admin','admin1')));//设置admin管理员 ...
- yii2.0中数据缓存之增删改查
public function actionSss(){ /* * 获取到缓存 * 这里是获取的是根目录下 的common/main.php中的缓存类组件 * */ $cache=\Yii::$app ...
- yii2.0中解决post的400错误
不想用gii的表单自己写表单,但是又遇到了400错误,怎么解决?下面为你解答一下:
- 在yii2.0中封装一个生成验证码的控制器
frontend目录下/封装的验证码类: <?php namespace frontend\controllers; use yii\base\Controller; class CapathC ...
- Yii2.0中form->field如何获取主表的一个字段并且设置为只读
<?= $form->field($model, 'last_login_time')->textInput(['readonly' => 'true']) ?>
随机推荐
- Rediss_基本介绍
Redis是典型的NoSQL数据库( Not Only SQL) NoSQL数据库: NoSQL,泛指非关系型的数据库.随着互联网web2.0网站的兴起, 传统的关系数据库在应付web2.0网站, 特 ...
- PHP中如何防止SQL注入
这是StackOverFlow上一个投票非常多的提问 How to prevent SQL injection in PHP? 我把问题和赞同最多的答题翻译了下来. 提问:如果用户的输入能直接插入到 ...
- Oracle Linux 6.3下安装Oracle 11g R2(11.2.0.3)
本文主要描写叙述了在Oracle Linux 6.3下安装Oracle 11gR2(11.2.0.3).从Oracle 11g開始,Oracle官方站点不再提供其Patch的下载链接,须要使用Meat ...
- 【转】C++ 类中的static,const,及引用类型的初始化
文档主要来自:http://blog.csdn.net/yjkwf/article/details/6067267 1. static类型 用static可以为类类型的所有对象所共有,像是全局对象,但 ...
- SQL Server将一列的多行内容拼接成一行的问题讨论
转自http://blog.csdn.net/rolamao/article/details/7745972 昨天遇到一个SQL Server的问题:需要写一个储存过程来处理几个表中的数据,最后问题出 ...
- CCLabelTTF 如何支持换行符和换行
参考自http://www.cocos2d-x.org/wiki/How_does_CCLabelTTF_support_line_breaks_and_wrapping 环境: cocos2d-x ...
- android微信简单界面
这几天没事做了一个简单的菜单布局,在这里我没有添加任何的功能只是做了一个简单的布局.看着还可以,就想着与大家分享一下. 代码如下: <LinearLayout xmlns:android=&qu ...
- sqlserver 连不上的问题
tcp ip 属性 ipall 属性改为1433
- magento中的一些技巧
1.加载某个attribute: $attributeCode=Mage::getModel('catalog/resource_eav_attribute') ...
- String sql = "update web_admin set adminname=? ,password=? where id=?;怎么给“?” 传值?
PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES ...