1

これは最近のホットトピックであり、自分のサイト用にjQueryMobileに基づいたテンプレートを作成する必要があります。テンプレートの作成は問題ではありませんが、誰かがモバイルデバイスを介してナビゲートするときに問題が発生することを示します。私はそれを行うために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:\ Webserver \ htdocs \ portal / catalog / view / theme / libcommerce_mobile /警告:require(D:\ Webserver \ htdocs \ portal \ catalog \ view \ theme \ libcommerce_mobile):ストリームを開くことができませんでした:許可77行目のD:\ Webserver \ htdocs \ portal \ system \ engine \ controller.phpで拒否されました致命的なエラー:require()[function.require]:必要なものを開くことができませんでした'D:\ Webserver \ htdocs \ portal / catalog / view / 77行目のD:\ Webserver \ htdocs \ portal \ system \ engine\controller.phpのtheme/libcommerce_mobile /'(include_path ='。;D:\ Webserver \ php \ PEAR')

しかし、ディレクトリが存在し、それが読み取り可能であることを驚かせてください、これに関する助けはありますか?私が間違っているのは何ですか?もう一度乾杯

PS:ここに投稿されたこのトピックから来ていますhttp://forum.opencart.com/viewtopic.php?f=20&t=47124

4

1 に答える 1

1

問題は、$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;
            }
        }
    }
于 2011-11-29T15:52:41.680 に答える