Opencart:CSS(基于路线维护)
这是我的第一个问题。我为我的网上商店使用Opencart。为了看起来我正在设计我的页面的CSS,例如account_login.css。但我也想做维护页面。我已经制作了common_maintenance.css文件。但是当我测试我的网站时显示不正确。它只是显示http://www.mywebsite.com而不是http://www.mywebsite.com/index.php?route=common/maintenance。请有人能帮我解决这个问题吗?Opencart:CSS(基于路线维护)
<?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 ='blahblah');
<?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());
}
}
}
感谢巴里,但它没有奏效。我收到以下消息:解析错误:语法错误,在第56行/home/theshopspot.nl/public_html/theshopspot/catalog/controller/common/maintenance.php中意外的'}'。当删除这一行时,我得到了以下错误:致命错误:类'User'在第15行中的/home/theshopspot.nl/public_html/theshopspot/catalog/controller/common/maintenance.php中找不到。我不知道该怎么做。顺便说一句,我的css文件被命名为common_maintenance.css。有任何建议吗? @BerryLangerak – coen1234 2012-03-09 17:09:34
@BarryLangerak它已经解决了!我把你的代码:$ css ='catalog/view/theme /'。 $ this-> config-> get('config_template')。 '/stylesheet/common_maintenance.css'; $ this-> document-> addStyle($ css);并将其放在原始的php文件中。这就是诀窍!十分感谢! – coen1234 2012-03-09 17:18:28
@ coen1234一旦它解决了您的问题,接受答案就是标准。并欢迎您:) – 2012-03-12 08:06:19
问题是您使用的是维护模式在维护模式下不会更改的路由。你需要做的是在维护控制器中使用$this->document->addStyle()
方法专门添加样式表。
您是否配置了URL重写? – 2012-03-07 18:55:16
你是如何改变css的?这需要更多的信息 – 2012-03-07 20:00:47
这些页面在catalog/controller/common/header.php中加载了自己的CSS,并在这个代码后面,在行保护函数index()之后(换行):$ route = empty($ this-> request - > get ['route'])? 'common/home':$ this-> request-> get ['route']; $ css_file = str_replace('/','_',$ route)。 ”的CSS; (file_exists(DIR_TEMPLATE。$ this-> config-> get('config_template')。'/ stylesheet /'。$ css_file)){this-> document-> addStyle('catalog/view/theme/'。$ this-> config-> get('config_template')。'/ stylesheet /'。$ css_file); } @JayGilford – coen1234 2012-03-08 08:22:47