【问题标题】:Time driven event in CodeigniterCodeigniter 中的时间驱动事件
【发布时间】:2015-06-30 09:23:34
【问题描述】:

我正在尝试在 Codeigniter 中实现一个函数,该函数在每个月底之后调用,以便它可以提醒用户支付费用。我如何在 Codeigniter 中实现这一点。谢谢。

【问题讨论】:

  • 到目前为止,您为实现这一目标做了哪些尝试?
  • 你可以每周使用ajax调用...setintervel
  • 我的想法是在数据库中插入一个日期,然后在每次用户加载页面时检查它,但这不是一个好主意,因为它是手动的,所以人们可能会忘记在数据库
  • 使用 ajax setinterval 时我将如何处理月份,因为有些月份可能有不同的日子?
  • 更好的方法是使用设置一个 cron 作业。只需在其中创建一个控制器和一个函数,因此您可以为此创建一个 url。并在 cron 作业中设置此 url。

标签: php codeigniter datetime


【解决方案1】:

您需要在每个月底创建 crontab 作业并调用 Your 方法(您可以在 crontab 中设置)。您可以通过

访问 CodeIgniter 方法

php5 index.php yourcontroller yourmethod

还要确保在您的方法中检查请求是否来自 CLI:

<?php

class Yourcontroller extends CI_Controller {

     function index(){

     }

  function yourmethod(){
    if(!$this->input->is_cli_request())
       die('CLI only');
    // add Your code below like this:
    $this->load->model('remindermodel');
    $this->remindermodel->remindToPay();
  }

}
?>

【讨论】:

  • 在我的 script.bat 中我应该这样编辑它吗? "C:\xampp\php" -f "C:\xampp\htdocs\Test1.1\application\controllers\CronController\myMethod"
  • @user3278647 不,类似于"C:\xampp\php" -f "C:\xampp\htdocs\Test1.1\index.php" CronController myMethod 。您需要执行 index.php 并向其发送参数。并检查 php 的路径,我认为在 Windows 中它必须包含 php.exe (C:\xampp\php\php.exe)
猜你喜欢
  • 2023-03-22
  • 2015-11-20
  • 2020-11-17
  • 1970-01-01
  • 2016-06-21
  • 1970-01-01
  • 2011-12-01
  • 1970-01-01
  • 2023-03-31
相关资源
最近更新 更多