如何将变量添加到controller/header.php中

3

我有一个网站,想要在头部添加一些标签以便于SEO。H1标题必须包含制造商名称(品牌)和产品代码(型号)。

问题是我不确定如何将这些变量放入控制器文件中,以便于在模板文件中调用它们。

有什么想法吗?:)


你使用的是哪个模板系统? - Cups
Opencart 1.5.1.3(它在标签中) - Aaviya
2个回答

1
最好的方法是编辑产品控制器。
catalog/controller/product/product.php

并更改标题。 它已设置为

$this->document->setTitle($product_info['name']);

所以你只需要在那里添加厂商的名称,例如

$this->document->setTitle($product_info['name'] . ' ' . $product_info['manufacturer']);

嗨,谢谢回复,但那不是重点。Timer.bg - 那是网站,我想在标志上方添加一些<h1>句子。我需要它对用户可见。 我在header.tmp中添加了此代码 <?php echo $manufacturer['name']; ?> <?php echo $product['model']; ?>,我还需要在controller/common/header.php中添加一些代码。 关键是这段代码应该长什么样 :) - Aaviya
这将会更加繁琐。您需要在文档类中添加一个新的方法,从产品控制器中分配制造商,并在标题中检索并将其添加到视图中。 - Jay Gilford

0

完成了!将此代码添加到controller/common/header.php文件中

if (isset($this->request->get['product_id'])) {
        $product_id = $this->request->get['product_id'];
    } else {
        $product_id = 0;
    }

    $this->load->model('catalog/product');

    $product_info = $this->model_catalog_product->getProduct($product_id);

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

    if ($product_info) {

        $this->data['manufacturer'] = $product_info['manufacturer'];
        $this->data['model'] = $product_info['model'];

    }

将此内容添加到 theme/default/template/common/header.tpl 文件中

<?php echo $product_info['manufacturer']; ?> <?php echo $product_info['model']; ?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接