从 opencart 2.0.3.1 中的 .tpl 文件引用 $this 时出错

Error refering to $this from a .tpl file in opencart 2.0.3.1

我使用 vqmod 将此代码注入 header.tpl。

<?php if ($this->customer->isLogged()){ if($this->customer->getCustomerGroupId()!=1) { ?>
              //show something

<?php } ?>

它在 opencart 1.5.6.1 中运行良好但现在我更新到 2.0.3.1 并且出现此错误:

Notice: Undefined property: Loader::$customer in C:\UniServerZ\www\opencart-2.0.3.1\upload\vqmod\vqcache\vq2-catalog_view_theme_default_template_common_header.tpl

有没有办法从 2.0.3.1 中的 .tpl 文件引用 $this ?

您不能从 tpl 呼叫客户 class,您已经在 header.php, 中这样做了 将数据存储到 $this->data[] 并在 tpl 文件中使用它。这将是正确的程序。

如果你想在 OC 中使用 .tpl 文件中的任何库文件,那么你必须先创建那个实例 class 然后你才能访问它,试试这个

$customer = new Customer();
$customer->isLogged()

最新版opencart(ver 2.x) 移除$this概念。所以你将直接使用

$customer->isLogged()