这是当今的热门话题,我需要为我的网站构建基于jQuery手机的模板。构建模板不是问题,而是显示某人何时导航槽移动设备。我知道我需要在OC核心中更改一些代码才能做到这一点,但需要一些建议或帮助。首先,加载模板的位置是/system/engine/controller.php。这是功能:

    protected function render() {
      foreach ($this->children as $child) {
         $this -> data[basename($child)] = $this -> getChild($child);
      }

      if (file_exists(DIR_TEMPLATE . $this -> template)) {
         extract($this -> data);
         ob_start();
         require (DIR_TEMPLATE . $this -> template);
         $this -> output = ob_get_contents();
         ob_end_clean();
         return $this -> output;
      } else {
         exit('Error: Could not load template ' . DIR_TEMPLATE . $this -> template . '!');
      }
   }

好的,我管理如何交易以检查用户代理是否是移动设备,这就是结果:

 protected function render() {
      foreach ($this->children as $child) {
         $this -> data[basename($child)] = $this -> getChild($child);
      }

      //--------- ADDED -------------------------------------------------
      if ($this -> config -> get('mobile_status') == 1) {
         if (($this -> isMobile() && $this -> config -> get('autodetect') == 'true') || $this -> session -> data['ismobile'] == 1) {
            $mobile_template = $this -> config -> get('mobile_template_name');
            if ($mobile_template != '') {
               if (!function_exists('is_dir') || (function_exists('is_dir') && is_dir(DIR_TEMPLATE . $mobile_template))) {
                  $this -> template = $mobile_template . "/";
               }
            }
         }
      }
      //--------- ADDED -------------------------------------------------

      if (file_exists(DIR_TEMPLATE . $this -> template)) {
         extract($this -> data);
         ob_start();
         require (DIR_TEMPLATE . $this -> template);
         $this -> output = ob_get_contents();
         ob_end_clean();
         return $this -> output;
      } else {
         exit('Error: Could not load template ' . DIR_TEMPLATE . $this -> template . '!');
      }
   }

现在,当我尝试使用移动用户代理进行加速时,我会收到此错误:

D: Weberver htdocs portal/catalog/view/theme/libcommerce_mobile/parning:require(d: weberver htdocs htdocs portal portal catalog catalog theme theme theme theme libcommerce_mobile_mobile)在D: Weberver htdocs portal portal system egine Engine Contranter.php中拒绝在第77行错误错误: them/libcommerce_mobile/'(include_path ='。;d: weberver php pear')in D: weberver htdocs htdocs portal portal portal portal ement Engine Engine controller.php在第77行上

但是,目录的存在令人惊讶,它是可读的,对此有任何帮助吗?我在做什么错?再欢呼一次

PS:来自此主题发布在这里 http://forum.opencart.com/viewtopic.php?f=20&t=47124

有帮助吗?

解决方案

问题是 $this->template 包含文件的整个路径,而不仅仅是模板目录。你应该做这样的事情

    if($this->config->get('mobile_status') == 1) {
        if(($this->isMobile() && $this->config->get('autodetect') == 'true') || $this->session->data['ismobile'] == 1) {
            $template = preg_replace('~^[^/]+~', $this->config->get('mobile_template_name'), $this->template);
            if(file_exists(DIR_TEMPLATE . $template) && !is_dir(DIR_TEMPLATE . $template)) {
                $this->template = $template;
            }
        }
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top