duanfu5239 2012-07-04 17:43
浏览 166
已采纳

如何将变量添加到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).

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? :)

  • 写回答

2条回答 默认 最新

  • dpcj32769 2012-07-09 08:09
    关注

    Did it! Added this code to 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

    <?php echo $product_info['manufacturer']; ?> <?php echo $product_info['model']; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料