0

I am use <?php $this->load->model('tool/image'); ?> this on tpl file i am getting this error Call to a member function model() on a non-object in /home/host/public_html/site/admin/view/template/module/module_name.tpl

any one please solve my problem

thanks

Jay Gilford
  • 15,141
  • 5
  • 37
  • 56
sarath
  • 9
  • 2
  • 4
  • You can't use `$this->` in your templates in opencart 2.0. There are [hacks like this](http://stackoverflow.com/questions/27158891/using-opencart-2-0-how-do-i-display-customers-email-on-a-category-page/27159228#27159228) to do this, but aren't recommended. All of your code like that should be in your controller file for your module, and any image resize etc should also be in there – Jay Gilford Jan 01 '15 at 15:58

2 Answers2

0

The error means that $this->load is not what you think it is.

I've looked at the docs briefly and the model property is available only inside the controller. You are trying to access it in the view. You need to pass the model object to the view.

Try this in the controller

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

Then in the view you should be able to do this:

<?php $load->model('tool/image'); ?>
Rupert
  • 1,629
  • 11
  • 23
  • Hello thanks for answer me... But its not working ... in opencart 1.5 vertion `load->model('tool/image'); ?>`is working .. but in opencart 2.0 vertion not working – sarath Jan 01 '15 at 13:22
0

I solve this suppressing the load call, I believe that now thee tpl is executed in the load, then when you call $this->load, you are calling load in load. If you put

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

it should to work, at least it worked in my code...

pcha
  • 78
  • 6