2016-08-24 102 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;