【发布时间】:2019-05-07 00:59:50
【问题描述】:
我很难让变量显示在 Opencart 的产品页面上。我在 catalog/model/catalog/product.php 文件中添加了一个 SQL 查询,如下所示:
public function getLargeItems($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "oc_product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id=17 AND (text LIKE '10lt' OR text LIKE '30lt' OR text LIKE '50lt')");
return $query->row;
}
然后我将以下内容添加到目录/控制器/产品/product.php 文件中:
$large_items = $this->model_catalog_product->getLargeItems($product_id);
最后我将以下内容添加到 /catalog/view/theme/mytheme/template/product/product.tpl 页面:
<?php if ($large_items) { ?>
<h1>Tree</h1>
<?php } ?>
它返回未定义的变量:/catalog/view/theme/mytheme/template/product/product.tpl 中的 large_items
我现在有点不知所措。有人能通过我的代码看到为什么它无法从控制器中提取变量吗?
我尝试通过将 $large_items = "Hello" 添加到控制器来简化它,以查看是否可以在视图页面上回显它,但它仍然看不到变量。
Opencart的版本是2.3.0.2
感谢您的宝贵时间。
【问题讨论】:
标签: model-view-controller view model controller opencart