WHMCS 6 升级:将多维 $this->_tpl_vars 转换为新参数 $template->getVariable

WHMCS 6 Upgrade: Converting a multi-dimensional $this->_tpl_vars to the new parameter $template->getVariable

我在我的一个自定义模板上将 WHMCS 5 升级到 WHMCS 6 时遇到了问题。

PHP 块的模板迁移说明之一,如 HERE 所述:

示例:

{php}

// Retrieve a single template variable. 
$myValue = $this->_tpl_vars['myVariable'];

// Loop through all template variables.
foreach ($this->_tpl_vars as $key => $value) {
   echo "{$key}: {$value}";
}

// Assign a new template variable.
$this->assign('myNewVariable', 'myNewValue');

{/php}

转换为:

{php}

// Retrieve a single template variable. 
$myValue = $template->getVariable('myVariable')->value;

// Loop through all template variables. 
foreach ($template->getTemplateVars() as $key => $variable) {
   echo "{$key}: {$variable->value}";
}

// The assign() method works as it did before, though it must now be 
// called on the $template object instead of $this.
$template->assign('myNewVariable', 'myNewValue');

{/php}

现在的问题是这样的。我将如何转换多维 $this->_tpl_vars ? 或者更具体地说,我将如何转换如下代码:

$email = $this->_tpl_vars['clientsdetails']['email'];

我正在查看新的 $client 对象,但也不确定如何使用它以及如何从中检索电子邮件信息。

希望有人能帮助我。谢谢!

In PHP 5.4 dereferencing was introduced,所以你应该可以做到:

$email = $template->getTemplateVars()['clientsdetails']['email'];

你可以这样使用。

$email = $template->getVariable('clientsdetails')->value['email'];