如何比较Silvrerstripe模板中的日期和当前日期?

时间:2018-04-13 07:27:12

标签: silverstripe

在Silverstripe模板中,我需要将变量$ date_ok与当前日期进行比较,如下所示:if($ date_ok< date(" j,n,Y"){...};

<% loop $IzdMat %>
<tr>
      <td>$num</td>
      <td>$sert_otip </strong> <br>Valid from $date_start  till  
$date_ok</td> 
      <% if $date_ok < ****** %>
         ..............
       <% end_if %> 
.......                                           

我必须写些什么内容?

1 个答案:

答案 0 :(得分:2)

您可以向DataObject添加方法,而不是尝试在模板中执行复杂的逻辑。这假设date_ok$db数组中定义的日期字段。

class IzdMat extends DataObject {

  public function IsDateOk() {
    $today = date("Y-m-d");
    return (strtotime($today) < strtotime($this->date_ok));
  }
}

然后在你的模板中。

<% loop $IzdMat %>
  <tr>
      <td>$num</td>
      <td>$sert_otip </strong> <br>Valid from $date_start  till  
$date_ok</td> 
      <% if $IsDateOk  %>
         ..............
      <% end_if %> 
  </tr>
<% end_loop %>
相关问题