英文:
Get PHP data on TPL file
问题
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 ...
我是新手 WHMCS 和 PHP,我想添加一个新的自定义 PHP 文件,用于显示所有顶级域名和它们的价格...
For that, i have created a new file : domainList.php under /public_html/ directory :
为此,我创建了一个新文件: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 文件中,我有以下代码:
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
但我无法直接从 PHP 文件中将变量 $response 填充到 tpl 文件中
i would like to send an array from php to tpl file and loop through it and display it in the tpl file
我想从 PHP 发送一个数组到 tpl 文件,然后在 tpl 文件中循环并显示它
response contains the following data :
响应包含以下数据:
英文:
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 :
答案1
得分: 2
我建议你丢弃$response,它可能是空的或格式不正确。
正如@MarkusZeller所说,将$jsonData
分配给response
更合乎逻辑。
请注意,如果提供的数据无法解码,json_decode()
会返回null。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论