简体   繁体   English

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

[英]How to add variable into controller/header.php

I have this site and I want to put some in header for SEO purposes. 我有这个网站,我想把一些标题用于搜索引擎优化目的。 The H1 must contain manufacturer name (brand) and product code (model). H1必须包含制造商名称(品牌)和产品代码(型号)。

So the problem is that I'm not sure how to put this variables in controller's file so I could call them in template file next. 所以问题是我不知道如何将这些变量放在控制器的文件中,所以我可以在模板文件中调用它们。

Any ideas? 有任何想法吗? :) :)

The best way around this would be to edit the product controller 解决此问题的最佳方法是编辑产品控制器

catalog/controller/product/product.php

and change the heading there. 并改变那里的标题。 It's set with 它设置为

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

so you just need to prepend/append the manufacturer name there, such as 所以你只需要在那里添加/附加制造商名称,例如

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

Did it! 做到了! Added this code to controller/common/header.php 将此代码添加到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'];

    }

And this to theme/default/template/common/header.tpl 这到theme / default / template / common / header.tpl

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM