Reputation: 11
I am new to WHMCS and php and i would like to add a new custom php file that displays all the tlds and their pricing ...
For that, i have created a new file : domainList.php under /public_html/ directory :
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 :
in the domainList.tpl file i have the following code :
{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
reponse contains the following data :
Upvotes: 1
Views: 111
Reputation: 5254
I suggest you to dump $response, it could be empty or not well formed.
As @MarkusZeller said it's more logical assigning $jsonData
to response
.
Note that json_decode()
returns null if provided data can't be decoded.
Upvotes: 2