代码之家  ›  专栏  ›  技术社区  ›  Anonymous

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

  •  -1
  • Anonymous  · 技术社区  · 10 年前

    使用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的方法?

    3 回复  |  直到 10 年前
        1
  •  5
  •   Tanmoy    10 年前

    你不能从tpl调用客户类,你必须在 header.php, 将数据存储到 $this->data[] 并在tpl文件中使用它。这将是正确的程序。

        2
  •  0
  •   Nipun Tyagi    10 年前

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

    $customer = new Customer();
    $customer->isLogged()
    
        3
  •  0
  •   Vipul Jethva    10 年前

    最新的opencart(版本2.x)删除了$this概念。所以您将直接使用

    $customer->已记录()

    推荐文章