【问题标题】:Open Cart Header position error打开购物车标题位置错误
【发布时间】:2013-12-05 10:49:40
【问题描述】:

我一直在尝试在 opencart 中的标题中添加一个位置,我想在其中放置一个横幅。所以这是我到目前为止所做的。

我在这里打开banner模块的语言文件/admin/language/english/module/输入以下代码

$_['text_headerbanner']       = 'headerbanner';

接下来我在 /admin/view/template/module/ 打开横幅模块管理模板并添加以下代码。

<?php if ($module['position'] == 'headerbanner') { ?>
<option value="headerbanner" selected="selected"><?php echo $text_headerbanner; ?>       </option>
<?php } else { ?>
<option value="headerbanner"><?php echo $text_headerbanner; ?></option>
<?php } ?>

并且还添加到第 140 行的 javascript 部分

  html += '      <option value="headerbanner"><?php echo $text_headerbanner; ?></option>';

然后在这里打开模块控制器文件/admin/controller/module/并进入

$this->data['text_headerbanner'] = $this->language->get('text_headerbanner');

这使我能够将新创建的横幅分配给我的管理端的“headerbanner”位置。

现在我继续将位置添加到模板中,我担心这一切都变得不稳定

所以我导航到 /catalog/controller/common/home.php 并添加了

'common/content_middle',

作为倒数第二个数组项,因此最后是逗号。 然后我在 /catalog/controller/common/ 中创建了一个名为“headerbanner.php”的 .php 文件,其中包含以下代码 -

<?php
class ControllerCommonheaderbanner extends Controller {
public function index() {
    $this->load->model('design/layout');
    $this->load->model('catalog/category');
    $this->load->model('catalog/product');
    $this->load->model('catalog/information');

    if (isset($this->request->get['route'])) {
        $route = $this->request->get['route'];
    } else {
        $route = 'common/home';
    }

    $layout_id = 0;

    if (substr($route, 0, 16) == 'product/category' && isset($this->request- >get['path'])) {
        $path = explode('_', (string)$this->request->get['path']);

        $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
    }

    if (substr($route, 0, 15) == 'product/product' && isset($this->request->get['product_id'])) {
        $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
    }

    if (substr($route, 0, 23) == 'information/information' && isset($this->request->get['information_id'])) {
        $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
    }

    if (!$layout_id) {
        $layout_id = $this->model_design_layout->getLayout($route);
    }

    if (!$layout_id) {
        $layout_id = $this->config->get('config_layout_id');
    }

    $module_data = array();

    $this->load->model('setting/extension');

    $extensions = $this->model_setting_extension->getExtensions('module');

    foreach ($extensions as $extension) {
        $modules = $this->config->get($extension['code'] . '_module');

        if ($modules) {
            foreach ($modules as $module) {
                if ($module['layout_id'] == $layout_id && $module['position'] == 'headerbanner' && $module['status']) {
                    $module_data[] = array(
                        'code'       => $extension['code'],
                        'setting'    => $module,
                        'sort_order' => $module['sort_order']
                    );
                }
            }
        }
    }

    $sort_order = array();

    foreach ($module_data as $key => $value) {
        $sort_order[$key] = $value['sort_order'];
    }

    array_multisort($sort_order, SORT_ASC, $module_data);

    $this->data['modules'] = array();

    foreach ($module_data as $module) {
        $module = $this->getChild('module/' . $module['code'], $module['setting']);

        if ($module) {
            $this->data['modules'][] = $module;
        }
    }

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/headerbanner.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/common/headerbanner.tpl';
    } else {
        $this->template = 'default/template/common/headerbanner.tpl';
    }

    $this->render();
}
}
?>

所以我继续在 /view/theme/beautyshop/template/common/ 中为此代码创建相应的 headerbanner.tpl 文件,其中包含此代码 -

<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>

然后在我的美容店标题模板中使用 -

调用它
<?php echo $headerbanner; ?>

我收到此错误

Notice: Undefined variable: headerbanner in /home/demodeto/public_html/catalog/view/theme/beautyshop/template/common/header.tpl on line 702

header.tpl 的代码有 1000 行长,但这里是被调用位置的基本 sn-p

?>
<?php echo $headerbanner; ?>
<div id="menu" class="clearfix">
<?
// custom block
if(($this->config->get('beauty_status') == '1')&&($this->config-     >get('beauty_layout_custommenu_block') == 1)&&($this->config-   >get('beauty_layout_custommenu_block_position') == 0))
{

if($this->config->get('beauty_layout_custommenu_block_title')<>'') echo '<li class="li-    custom-block"><a>'.$this->config->get('beauty_layout_custommenu_block_title').'</a><div    class="custom-topmenu-block"><ul><li>'.html_entity_decode($this->config-   >get('beauty_layout_custommenu_block_content')).'</li></ul></div></li><li    class="separator"></li>';

}
?>

我对 PHP 了解的不够多,无法调试此代码尝试定义变量的位置,任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: php variables opencart


    【解决方案1】:

    答案很简单:你错过了header 控制器的孩子:

    catalog/controller/common/header.php 几乎在最后找到这个数组:

        $this->children = array(
            'module/language',
            'module/currency',
            'module/cart'
        );
    

    现在您必须添加您的新孩子:

        $this->children = array(
            'module/language',
            'module/currency',
            'module/cart',
            'common/headerbanner'
        );
    

    这应该可以完成工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多