0

ファイル 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 ファイルを作成する必要があることです。 質問に戻りますが、 これをエレガントに行う別の方法はありますか?

4

1 に答える 1