【问题标题】:codeigniter update register based on date基于日期的codeigniter更新寄存器
【发布时间】:2015-02-11 10:42:22
【问题描述】:

我正在开发一个新闻应用程序,用户可以在其中介绍新闻并存储创建日期,并且新闻会显示“新!”旁边的图标。我想在新闻变旧时(比如说 1 周)自动删除“新”图标。

如何自动实现此功能? 我想根据“比用户介绍新闻的时间晚 1 周”来更新表的字段(例如新字段)。

我是否需要为每个创建的新寄存器设置一个“计时器”?我是否需要某种 cron 作业来检查新闻是否过时?

你会怎么做?

谢谢!

【问题讨论】:

  • 为什么需要新身份?你可以用时差来显示它。参见@AdrienXL 解决方案

标签: codeigniter timer cron jobs


【解决方案1】:

由于您没有提供任何代码,因此不确定您的应用是如何工作的,但您可以在自己的视图中轻松完成:

if(time() - strtotime($postDate) <= 60*60*24*7) //$postDate is the date stored in your table 
{
   echo "<div>new!</div>"
}

如果您想使用 db 字段来执行此操作,请查看 crons 的工作原理:

https://en.wikipedia.org/wiki/Cron

【讨论】:

    【解决方案2】:

    您可以尝试以下方法:

    $news_time = strtotime($row['creation_date']); // your database record creation date
    $a_week_ago = strtotime('-1 week');
    
    if( $news_time > a_week_ago ) { 
    // Your 'new' HTML here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多