Post by Cue4cheap » Thu May 07, 2020 9:26 am

I am converting from 1.5.6.4 to 2.3.0.2 and at one time I had a specific call in the product.tpl file.
I put the same in the 2.3.0.2 product.tpl file and I get the error: PHP Notice: Undefined property: Template\PHP::$load in /public_html/system/storage/modification/catalog/view/theme/default/template/product/product.tpl on line 48
Is loading a model in the tpl file no longer allowed?
BTW here is the code:

Code: Select all

<?php
$this->load->model('catalog/category');	
$product_cat2 = $this->model_catalog_product->getCategories($product_id);
$result = $this->db->query("
SELECT
    `c`.`parent_id`
FROM
    `" . DB_PREFIX . "category` `c`
LEFT JOIN
    `" . DB_PREFIX . "product_to_category` `p2c`
ON
    `c`.`category_id` = `p2c`.`category_id`
WHERE
    (`c`.`parent_id` = '1' OR `c`.`parent_id` = '1112')
AND
    `p2c`.`product_id` = '" . (int) $product_id . "'
");
But it chokes on it now.
How would be best to now go about this?
Thank you,
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Cue4cheap » Thu May 07, 2020 9:39 am

Nevermind... I should just do it the right way and not hack it with the code in the tpl. It was wrong when I first did it years ago and I guess is now being enforced.
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by OSWorX » Thu May 07, 2020 4:12 pm

Cue4cheap wrote:
Thu May 07, 2020 9:26 am
Is loading a model in the tpl file no longer allowed?
Any direct calls for models, controllers etc. inside any template (does no matter if .tpl and/or .twig) should be avoided!
Whenever needed, place your logic inside the controller and handover the data to the template.

btw: it was not correct before ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator
Online

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 4 guests