在 opencart 2.0 上出现非对象错误时调用成员函数 model()

Call to a member function model() on a non-object error on opencart 2.0

我在 tpl 文件上使用 <?php $this->load->model('tool/image'); ?> 我收到这个错误 Call to a member function model() on a non-object in /home/host/public_html/site/admin/view/template/module/module_name.tpl

谁能解决我的问题

谢谢

错误的意思是$this->load不是你想的那样。

我简要地查看了文档,模型 属性 仅在控制器内部可用。您正在尝试在视图中访问它。您需要将模型对象传递给视图。

在控制器中试试这个

$this->data['load'] = $this->load;

那么在视图中你应该可以这样做:

<?php $load->model('tool/image'); ?>

我解决了这个抑制加载调用的问题,我相信现在你的 tpl 是在加载中执行的,那么当你调用 $this->load 时,你就是在加载中调用加载。 如果你把

$this->load->model('tool/image');

它应该可以工作,至少它在我的代码中工作...