如何比较 Silverstripe 模板中的日期和当前日期?
How compare date and current date in Silvrerstripe template?
在 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 %>
.......
我必须写什么代替******?
您可以向 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 %>
在 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 %>
.......
我必须写什么代替******?
您可以向 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 %>