假设我有一个文件 foo_version1.php 并且它是实时和发布的。我需要在未来的某个特定日期和时间向其中添加新内容。一旦发布日期等于今天的日期,有没有办法让新内容显示?
这是我到目前为止所做的......
<?php
//set the time zone to LA
date_default_timezone_set('America/Los_Angeles');
class Timelock{
var $fileName;
var $contentName;
var $publishDate;
function __construct($fileName, $contentName, $publishDate){
$this->contentName = $contentName;
$this->publishDate = $publishDate;
$this->fileName = $fileName;
}
function contentName(){
return $this->contentName;
}
function publishDate(){
return $this->publishDate;
}
function fileName(){
return $this->fileName;
}
}
//create objects that has certain publish date
$chargers = new Timelock("content1.php" ,"San Diego Chargers", "2013-10-18 16:41:00");
$colts = new Timelock("content2.php" ,"Indianapolis Colts", "2013-10-18 16:41:03");
$vikings = new Timelock("content3.php" ,"Minnesota Vikings", "2013-10-18 16:41:06");
$eagles = new Timelock("content4.php" ,"Philadelphia Eagles", "2013-10-18 16:41:09");
$cowboys = new Timelock("content5.php" ,"Dallas Cowboyws", "2013-10-18 16:41:12");
//add the contents with timelocks into the array
$contentArray = array();
$contentArray[] = $chargers;
$contentArray[] = $colts;
$contentArray[] = $vikings;
$contentArray[] = $eagles;
$contentArray[] = $cowboys;
//include the file if the publish date is today
foreach($contentArray as $obj){
if( strtotime($currentDate) >= strtotime($obj->publishDate())){
include ($obj->fileName());
}
}
?>
这样做的问题是,每次我需要添加不理想的新内容时,我都需要创建新的 php 文件。 那么回到这个问题 ,是否有另一个优雅地做到这一点?