Opencart:CSS(基于路由维护)


Opencart: CSS (based on route maintenance)

这是我在这里的第一个问题。我正在为我的网店使用Opencart。对于外观,我正在为我的页面设置CSS样式,例如account_login.CSS。但我也想做维护页面。我已经制作了common_matenance.css文件。但当我测试我的网站时,显示不正确。它只是在展示http://www.mywebsite.com而不是http://www.mywebsite.com/index.php?route=common/maintenance.有人能帮我吗?

<?php
class ControllerCommonMaintenance extends Controller {
 public function index() {
     if ($this->config->get('config_maintenance')) {            $route = '';
                    if (isset($this->request->get['route'])) {
            $part = explode('/', $this->request->get['route']);
            if (isset($part[0])) {
                $route .= $part[0];
            }                       }
                    // Show site if logged in as admin          $this->load->library('user');
                    $this->user = new User($this->registry);
            if (($route != 'payment') && !$this->user->isLogged()) {
            return $this->forward('common/maintenance/info');           }                       
     }
 }
        public function info() {
     $this->load->language('common/maintenance');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array(
         'text'      => $this->language->get('text_maintenance'),           'href'      => $this->url->link('common/maintenance'),
         'separator' => false
     ); 
     $this->data['message'] = $this->language->get('text_message');
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . 
 '/template/common/maintenance.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/common/maintenance.tpl';
     } else {
         $this->template = 'default/template/common/maintenance.tpl';        }
                $this->children = array(            'common/footer',            'common/header'         );
        $this->response->setOutput($this->render());
 } } ?>

我已经修复了丑陋的格式,并添加了对->addStyle($css)的调用。如果代码还不起作用,请检查我是否正确地找到了CSS的路径(上面写着$CSS='blablah');

<?php
class ControllerCommonMaintenance extends Controller {
    public function index() {
        if ($this->config->get('config_maintenance')) {
            $route = '';
            if (isset($this->request->get['route'])) {
                $part = explode('/', $this->request->get['route']);
                if (isset($part[0])) {
                    $route .= $part[0];
                }
            }
            // Show site if logged in as admin
            // $this->load->library('user');
            $this->user = new User($this->registry);
            if (($route != 'payment') && !$this->user->isLogged()) {
                return $this->forward('common/maintenance/info');
            }
        }
    }
    public function info() {
        $this->load->language('common/maintenance');
        $this->document->setTitle($this->language->get('heading_title'));
        $css = 'catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/common_maintenance.css';
        $this->document->addStyle($css);
        $this->data['heading_title'] = $this->language->get('heading_title');
        $this->document->breadcrumbs = array();
        $this->document->breadcrumbs[] = array(
            'text'      => $this->language->get('text_maintenance'),
            'href'      => $this->url->link('common/maintenance'),
            'separator' => false
        );
        $this->data['message'] = $this->language->get('text_message');
        $maintenance = $this->config->get('config_template') . '/template/common/maintenance.tpl';
        if (file_exists(DIR_TEMPLATE . $maintenance ) ) {
            $this->template = $maintenance;
        }
        else {
            $this->template = 'default/template/common/maintenance.tpl';         }
            $this->children = array(
                'common/footer',
                'common/header'
            );
            $this->response->setOutput($this->render());
        }
     }
}

问题是您使用的路由,当处于维护模式时,维护模式不会改变。您需要做的是使用$this->document->addStyle()方法

在维护控制器中专门添加样式表