doudieheng5322 2011-11-28 15:55
浏览 16
已采纳

为移动设备开发

This is a hot topic in this days and I need to build a template based on jQuery Mobile for my site. Build the template isn't the problem but show when someone navigate trough mobile devices is. I know I need to change some codes in OC core in order to do that but need some advice or help on this. First the place where the template is loaded is /system/engine/controller.php. This is the function:

    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 . '!');
      }
   }

Ok, I manage in how to deal to check if User Agent is Mobile Device or not and this is the result:

 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 . '!');
      }
   }

Now when I try to acces using a Mobile User Agent I get this error:

D:\Webserver\htdocs\portal/catalog/view/theme/libcommerce_mobile/Warning: require(D:\Webserver\htdocs\portal\catalog\view\theme\libcommerce_mobile) [function.require]: failed to open stream: Permission denied in D:\Webserver\htdocs\portal\system\engine\controller.php on line 77 Fatal error: require() [function.require]: Failed opening required 'D:\Webserver\htdocs\portal/catalog/view/theme/libcommerce_mobile/' (include_path='.;D:\Webserver\php\PEAR') in D:\Webserver\htdocs\portal\system\engine\controller.php on line 77

But surprise the directory exists and it's readable, any help on this? What I'm doing wrong? Cheers one more time

PS: Coming from this topic posted here http://forum.opencart.com/viewtopic.php?f=20&t=47124

展开全部

  • 写回答

1条回答 默认 最新

  • duanpan7011 2011-11-29 07:52
    关注

    The problem is that the $this->template contains the whole path of the file, not just the template directory. You should do something like this instead

        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;
                }
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目
  • ¥30 海外项目,如何降低Google Map接口费用?
  • ¥15 fluentmeshing
  • ¥15 手机/平板的浏览器里如何实现类似荧光笔的效果
  • ¥15 盘古气象大模型调用(python)
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部