2010-06-02 153 views
0

我有這樣的代碼捕獲日期和時間:顯示不同的模板

date('F j, Y, g:i a T') 

,並保存作爲

$datetime: 

,我有這樣的代碼包括模板:

function template_contents($file, $model) { 
    if (!is_file($file)) { 
     throw new Exception("Template not found"); 
    } 
    ob_start(); 
    include $file; 
    $contents2 = ob_get_contents(); 
    ob_end_clean(); 

    return $contents; 
} 

if($datetime == "No Date Yet"){ 
    echo template_contents("post.php", $model); 
} elseif($datetime == "June 2, 2010, 2:55 pm MDT"){ 
    echo template_contents("notpost.php", $model); 
}else { 
    echo template_contents("post.php", $model); 
} 

我的希望編輯ELSEIF語句顯示notpost.php模板,如果在$日期時間小於 2天。所以,notpost.php顯示兩天,post.php顯示兩天後。

+0

這是一個自動過程,你的控制日期是硬編碼? – Zuul 2010-06-02 22:07:10

回答

1

更改ELSEIF聲明:

} elseif (time() <= strtotime("June 2, 2010, 2:55 pm MDT")) { 

這notpost.php顯示,如果當前時間(由time()給出)比規定時間早。

+0

工作很好。謝謝! – Jon 2010-06-03 02:46:39