我是 WHMCS 和 php 的新手,我想添加一个新的自定义 php 文件来显示所有顶级域名及其定价 ...
为此,我创建了一个新文件:domainList.php 在 /public_html/ 目录下:
domainList.php
<?PHP
use WHMCS\Authentication\CurrentUser;
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle('Your Page Title Goes Here');
$ca->initPage();
$ca->setTemplate('domainList');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'GetTLDPricing',
// See https://developers.whmcs.com/api/authentication
'username' => 'GGT3m7EqO7bxnrb1HcT9i1z0tKOcmA03',
'password' => 'qRFYmqc7JDNprtGxFFwKBJzHyaGxMSbv',
'currencyid' => '1',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$jsonData = json_decode($response, true);
$ca->output();
$smarty->assign("response", $response);
?>
in the domainList.tpl file i have the following code :
在 domainList.tpl 文件中,我有以下代码:
{foreach $response['pricing'] as $tld => $price}{$tld} : {$price['register']['1']}{/foreach}
But i could not get the variable $response populated directly in the tpl file from the php file
i would like to send an array from php to tpl file and loop through it and display it in the tpl file
响应包含以下数据:
我建议你转储 $response,它可能是空的或者格式不正确。 正如@MarkusZeller所说,将
$jsonData
分配给response
更合乎逻辑。
请注意,如果无法解码提供的数据,json_decode()
将返回 null。