2015-12-05 17 views
-1

这段代码需要3个声音和更多的执行。这是不好的,我需要这个代码更快,并加快..请只是如果你有关于主题的经验给加快这个代码的情况。有没有什么办法来加速这个代码的顶级内容和页脚?

顶部内容代码:

class ControllerCommonContentTop extends Controller { 
    public function index() { 
     $this->load->model('design/layout'); 
     if (isset($this->request->get['route'])) { 
      $route = (string)$this->request->get['route']; 
     } else { 
      $route = 'common/home'; 
     } 
     $layout_id = 0; 

     if ($route == 'product/category' && isset($this->request->get['path'])) { 
      $this->load->model('catalog/category'); 

      $path = explode('_', (string)$this->request->get['path']); 

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

     if ($route == 'product/product' && isset($this->request->get['product_id'])) { 
      $this->load->model('catalog/product'); 

      $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']); 
     } 
     if ($route == 'information/information' && isset($this->request->get['information_id'])) { 
      $this->load->model('catalog/information'); 

      $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'); 
     } 
     $this->load->model('extension/module'); 

     $data['modules'] = array(); 

     $modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_top'); 

     foreach ($modules as $module) { 
      $part = explode('.', $module['code']); 

      if (isset($part[0]) && $this->config->get($part[0] . '_status')) { 
       $data['modules'][] = $this->load->controller('module/' . $part[0]); 
      } 

      if (isset($part[1])) { 
       $setting_info = $this->model_extension_module->getModule($part[1]); 

       if ($setting_info && $setting_info['status']) { 
        $data['modules'][] = $this->load->controller('module/' . $part[0], $setting_info); 
       } 
      } 
     } 
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/content_top.tpl')) { 
      return $this->load->view($this->config->get('config_template') . '/template/common/content_top.tpl', $data); 
     } else { 
      return $this->load->view('default/template/common/content_top.tpl', $data); 
     } 
    } 
} 

页脚代码:

class ControllerCommonFooter extends Controller { 
    public function index() { 
     $this->load->language('common/footer'); 

     $data['text_information'] = $this->language->get('text_information'); 
     $data['text_service'] = $this->language->get('text_service'); 
     $data['text_extra'] = $this->language->get('text_extra'); 
     $data['text_contact'] = $this->language->get('text_contact'); 
     $data['text_return'] = $this->language->get('text_return'); 
     $data['text_sitemap'] = $this->language->get('text_sitemap'); 
     $data['text_manufacturer'] = $this->language->get('text_manufacturer'); 
     $data['text_voucher'] = $this->language->get('text_voucher'); 
     $data['text_affiliate'] = $this->language->get('text_affiliate'); 
     $data['text_special'] = $this->language->get('text_special'); 
     $data['text_account'] = $this->language->get('text_account'); 
     $data['text_order'] = $this->language->get('text_order'); 
     $data['text_wishlist'] = $this->language->get('text_wishlist'); 
     $data['text_newsletter'] = $this->language->get('text_newsletter'); 

     $this->load->model('catalog/information'); 

     $data['informations'] = array(); 

     foreach ($this->model_catalog_information->getInformations() as $result) { 
      if ($result['bottom']) { 
       $data['informations'][] = array(
        'title' => $result['title'], 
        'href' => $this->url->link('information/information', 'information_id=' . $result['information_id']) 
       ); 
      } 
     } 

     $data['contact'] = $this->url->link('information/contact'); 
     $data['return'] = $this->url->link('account/return/add', '', 'SSL'); 
     $data['sitemap'] = $this->url->link('information/sitemap'); 
     $data['manufacturer'] = $this->url->link('product/manufacturer'); 
     $data['voucher'] = $this->url->link('account/voucher', '', 'SSL'); 
     $data['affiliate'] = $this->url->link('affiliate/account', '', 'SSL'); 
     $data['special'] = $this->url->link('product/special'); 
     $data['account'] = $this->url->link('account/account', '', 'SSL'); 
     $data['order'] = $this->url->link('account/order', '', 'SSL'); 
     $data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL'); 
     $data['newsletter'] = $this->url->link('account/newsletter', '', 'SSL'); 

     $data['powered'] = sprintf($this->language->get('text_powered'), $this->config->get('config_name'), date('Y', time())); 

     // Whos Online 
     if ($this->config->get('config_customer_online')) { 
      $this->load->model('tool/online'); 

      if (isset($this->request->server['REMOTE_ADDR'])) { 
       $ip = $this->request->server['REMOTE_ADDR']; 
      } else { 
       $ip = ''; 
      } 

      if (isset($this->request->server['HTTP_HOST']) && isset($this->request->server['REQUEST_URI'])) { 
       $url = 'http://' . $this->request->server['HTTP_HOST'] . $this->request->server['REQUEST_URI']; 
      } else { 
       $url = ''; 
      } 

      if (isset($this->request->server['HTTP_REFERER'])) { 
       $referer = $this->request->server['HTTP_REFERER']; 
      } else { 
       $referer = ''; 
      } 

      $this->model_tool_online->whosonline($ip, $this->customer->getId(), $url, $referer); 
     } 

     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/footer.tpl')) { 
      return $this->load->view($this->config->get('config_template') . '/template/common/footer.tpl', $data); 
     } else { 
      return $this->load->view('default/template/common/footer.tpl', $data); 
     } 
    } 
} 
+0

多少类别/子类别贵店有哪些?在早期的OpenCart版本(1.5.x)中,有太多类别和子类别导致类别计数功能需要很长时间才能运行。不知道它是否修复为v2或不是 – colmde

+0

我使用OpenCart版本2。我现在只有30个类别和300个产品。 –

+0

您可以使用付费第三方扩展来提高页面速度。 http://www.opencart.com/index.php?route=extension/extension/info&extension_id=6204&filter_search=speed&page=2 – HarnishDesign

回答

0

步骤从代码回来,考虑到整个页面交付。

很多时候,性能问题都可以得到解决如下:

  1. 压缩 - http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
  2. 缓存 - https://httpd.apache.org/docs/2.4/mod/mod_expires.html
  3. 图像的正确尺寸 - 确保图像在被发送差不多大小,因为它们将被渲染
  4. 缩小 - https://en.wikipedia.org/wiki/Minification_%28programming%29
  5. 减少请求数量 - 一个很好的例子是精灵
  6. 将JavaScript置于身体

这是一个伟大的工具来帮助你想办法让你的网页速度的结尾:http://www.websiteoptimization.com/services/analyze/

+0

感谢您的关注,但我认为这是从服务器端引起的,我的意思是只需将文档传递到浏览器需要很长时间。 –

相关问题