WHMCS Hook - foreach错误

时间:2016-11-09 14:41:41

标签: foreach smarty hook whmcs

我正在尝试制作一个钩子,我遇到了foreach函数的问题。

我收到以下错误,但我正在使用http://docs.whmcs.com/Email_Templates中的智能foreach函数。

// Call WHMCS API - send admin email 
$command = "sendadminemail"; 
$adminuser = "admin"; 
$values["customsubject"] = "Daily Cron Report"; 
$values["custommessage"] = "Domains Report<br>"; 
$values["custommessage"] .= "--------------------<br>"; 
$values["custommessage"] .= "{$active_domains_count} Active Domains<br>{$expired_domains_count} Expired Domains<br>"; 
$values["custommessage"] .= "--------------------<br>"; 
$values["custommessage"] .= "Expired Domains"; 
$values["custommessage"] .= "{foreach from=$expired_domains item=expireddomains}-{$expireddomains.domain}<br>{/foreach}"; 
$values["customvars"] = array("active_domains_count" => $active_domains_count, "expired_domains_count" => $expired_domains_count, "expired_domains" => $expired_domains); 
$values["type"] = "system"; 

$results = localAPI($command, $values, $adminuser);
  

解析错误:语法错误,意外'。',期待'}'   第24行/includes/hooks/dailycron.php

有什么建议吗?提前谢谢

1 个答案:

答案 0 :(得分:1)

使用php -l调试sintax错误,你的问题在第11行,用单引号关闭字符串而不是修复它的双字符串。

<?php
// Call WHMCS API - send admin email
$command = "sendadminemail";
$adminuser = "admin";
$values["customsubject"] = "Daily Cron Report";
$values["custommessage"] = "Domains Report<br>";
$values["custommessage"] .= "--------------------<br>";
$values["custommessage"] .= "{$active_domains_count} Active Domains<br>{$expired_domains_count} Expired Domains<br>";
$values["custommessage"] .= "--------------------<br>";
$values["custommessage"] .= "Expired Domains";
$values["custommessage"] .= '{foreach from=$expired_domains item=expireddomains}-{$expireddomains.domain}<br>{/foreach}';
$values["customvars"] = array("active_domains_count" => $active_domains_count, "expired_domains_count" => $expired_domains_count, "expired_domains" => $expired_domains);
$values["type"] = "system";

$results = localAPI($command, $values, $adminuser);