2016-08-24 103 views
0

我试图检查服务器的日期和时间与资源的日期电视compate,但我总是空白页时,我尝试检查IF statment,这里是我所需要的。镆铘IF返回空白页

我已经片断这样的

<?php 
function getDatetimeNow() { 
    $tz_object = new DateTimeZone('Europe/Belgrade'); 
    $datetime = new DateTime(); 
    $datetime->setTimezone($tz_object); 
    return $datetime->format('Y\-m\-d\ h:i:s'); 
} 

$currentDate = getDatetimeNow(); 

$dtA = new DateTime($currentDate); 
$dtB = new DateTime($date); 

if ($dtA > $dtB) { 
    $active = 0; 
    return $active; 
} 
else { 
    $active = 1; 
    return $active; 
} 

但是,当页面上,如果我尝试这样

[[!CheckCurrentDate? &date=`[[*DatumIsteka]]`]] 

我基于TV值* DatumIsteka得到1或0,所有的好的工作,但当我试图比较这样的

[[!If? 
    &subject=`[[!CheckCurrentDate? &date=`[[*DatumIsteka]]`]]` 
    &operator=`equals` 
    &operand=`0` 
    &then=`<script> 
    $("#tab3").html("<p>U Pripremi</p>"); 
    </script>` 
    ]] 

我得到了资源的白页?? 什么是问题,任何帮助将很好:)

+0

退房apache的错误日志。 – Vasis

+0

MODX错误日志中的任何东西? –

回答

0

改变你的操作员不等于和你的操作数到1 - modx电视实际上不存在,除非他们填充[即使他们有默认定义]如果电视没有填充,您的片段中可能会出现空值或错误。

OR

呼应你的返回值,

if ($dtA > $dtB) { 
    $active = 0; 
} 
else { 
    $active = 1; 
} 

echo $active; 

return; 

在有可能解释返回值作为布尔值与字符串有问题?

你也可以改变你的代码片段检索当前的资源DatumIsteka值,然后使用output modifiers

或者是这样的:

<?php 
function getDatetimeNow() { 
    $tz_object = new DateTimeZone('Europe/Belgrade'); 
    $datetime = new DateTime(); 
    $datetime->setTimezone($tz_object); 
    return $datetime->format('Y\-m\-d\ h:i:s'); 
} 

$currentDate = getDatetimeNow(); 

$dtA = new DateTime($currentDate); 

$date = $modx->resource->getTVValue('DatumIsteka'); 

$dtB = new DateTime($date); 

if ($dtA > $dtB) { 
    $active = $modx->getChunk('chunkName'); 
// chunkName = <script>$("#tab3").html("<p>U Pripremi</p>");</script> 
} 
else { 
    $active = 1; 
} 

echo $active; // you have to echo it if you are passing a string 

return;