获取TPL文件中的PHP数据

huangapple go评论65阅读模式
英文:

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 :
响应包含以下数据:

enter image description here

英文:

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

&lt;?PHP

use WHMCS\Authentication\CurrentUser;
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

define(&#39;CLIENTAREA&#39;, true);

require __DIR__ . &#39;/init.php&#39;;

$ca = new ClientArea();

$ca-&gt;setPageTitle(&#39;Your Page Title Goes Here&#39;);

$ca-&gt;initPage();


$ca-&gt;setTemplate(&#39;domainList&#39;);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, &#39;https://example.com/includes/api.php&#39;);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            &#39;action&#39; =&gt; &#39;GetTLDPricing&#39;,
            // See https://developers.whmcs.com/api/authentication
            &#39;username&#39; =&gt; &#39;GGT3m7EqO7bxnrb1HcT9i1z0tKOcmA03&#39;,
            &#39;password&#39; =&gt; &#39;qRFYmqc7JDNprtGxFFwKBJzHyaGxMSbv&#39;,
            &#39;currencyid&#39; =&gt; &#39;1&#39;,
            &#39;responsetype&#39; =&gt; &#39;json&#39;,
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$jsonData = json_decode($response, true);


$ca-&gt;output();
$smarty-&gt;assign(&quot;response&quot;, $response); 

?&gt;

in the domainList.tpl file i have the following code : 

in the domainList.tpl file i have the following code :

{foreach $response[&#39;pricing&#39;] as $tld =&gt; $price}{$tld} : {$price[&#39;register&#39;][&#39;1&#39;]}{/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 :

enter image description here

答案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.

huangapple
  • 本文由 发表于 2023年4月11日 03:05:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定