如何在登录页面设置背景图片(opencart 2.0.x)
how to set background image on login page (opencart 2.0.x)
我是 运行 opencart 2.0.3.1,我想在管理员登录页面上添加响应式背景图片(路线:common/login)。
我考虑通过编辑 /admin/view/template/common 上的 header.tpl 文件并在 body 标签上添加 php 条件,如果路由 = [,我在背景中添加 class =31=].
我的逻辑思维:
首先我想测试是否有路由(如果有!着陆页),如果有则检查它是否等于登录路由,如果是,则在标签上插入 "background-image" class。
这是我的 php 代码:
<?php
if( !isset($this->request->get['route']) ){
if( ((string)$this->request->get['route'] ) == "common/login" OR ( (string)$this->request->get['route'] )=="login" ){
echo('class="login-background"');
}
}
?>
这是我的 header.tpl 的正文标签:
<body
<?php
if( !isset($this->request->get['route']) ){
if( ( (string)$this->request->get['route'] )=="common/login" OR ( (string)$this->request->get['route'] )=="login" ){
echo('class="login-background"');
}
}
?>
>
这是我的 css:
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
color: #666666;
line-height: 18px;
text-rendering: optimizeLegibility;
}
body.login-background{
background-image:url(http://example.net/image/login-admin.jpg);
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
但是我得到这个错误:
Notice: Undefined index: route in "MYDIRECTORY"/vqmod/vqcache/vq2-admin_view_template_common_header.tpl on line 39
如果我没记错的话,问题出在“2nd if”上,但我不知道如何解决(如您所见,我仍然是一个 n00b。)
希望你能帮帮我!!
首先,在admin\controller\common\header.php的索引方法return
之前添加如下代码
$body_class = '';
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
if ( $route == 'common/login' || $route == 'login' )
$body_class = 'login-background';
}
$data['body_class'] = $body_class;
其次,修改admin\view\template\common\header.tpl上的body标签如下
<body class="<?php echo $body_class; ?>">
============================================= =====================
更新:
对不起,我的错,$this->request->get['route'] 无法通过 common\header.php 访问。这是在opencart 2.0.2.0上测试的更新方法:
在 admin\controller\common\header 上添加参数。php
public function index($args) {
在 admin\controller\common\header.php 的索引方法 return
之前添加以下代码
$body_class = '';
if (isset($args['route'])) {
$route = (string)$args['route'];
if ( $route == 'common/login' )
$body_class = 'login-background';
}
$data['body_class'] = $body_class;
传递参数给common/header,在admin\controller\common\login修改它。php
$data['header'] = $this->load->controller('common/header', array('route' => 'common/login'));
保持common\header.tpl的正文标签如下
<body class="<?php echo $body_class; ?>">
我是 运行 opencart 2.0.3.1,我想在管理员登录页面上添加响应式背景图片(路线:common/login)。 我考虑通过编辑 /admin/view/template/common 上的 header.tpl 文件并在 body 标签上添加 php 条件,如果路由 = [,我在背景中添加 class =31=].
我的逻辑思维: 首先我想测试是否有路由(如果有!着陆页),如果有则检查它是否等于登录路由,如果是,则在标签上插入 "background-image" class。
这是我的 php 代码:
<?php
if( !isset($this->request->get['route']) ){
if( ((string)$this->request->get['route'] ) == "common/login" OR ( (string)$this->request->get['route'] )=="login" ){
echo('class="login-background"');
}
}
?>
这是我的 header.tpl 的正文标签:
<body
<?php
if( !isset($this->request->get['route']) ){
if( ( (string)$this->request->get['route'] )=="common/login" OR ( (string)$this->request->get['route'] )=="login" ){
echo('class="login-background"');
}
}
?>
>
这是我的 css:
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
color: #666666;
line-height: 18px;
text-rendering: optimizeLegibility;
}
body.login-background{
background-image:url(http://example.net/image/login-admin.jpg);
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
但是我得到这个错误:
Notice: Undefined index: route in "MYDIRECTORY"/vqmod/vqcache/vq2-admin_view_template_common_header.tpl on line 39
如果我没记错的话,问题出在“2nd if”上,但我不知道如何解决(如您所见,我仍然是一个 n00b。)
希望你能帮帮我!!
首先,在admin\controller\common\header.php的索引方法return
之前添加如下代码 $body_class = '';
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
if ( $route == 'common/login' || $route == 'login' )
$body_class = 'login-background';
}
$data['body_class'] = $body_class;
其次,修改admin\view\template\common\header.tpl上的body标签如下
<body class="<?php echo $body_class; ?>">
============================================= =====================
更新:
对不起,我的错,$this->request->get['route'] 无法通过 common\header.php 访问。这是在opencart 2.0.2.0上测试的更新方法:
在 admin\controller\common\header 上添加参数。php
public function index($args) {
在 admin\controller\common\header.php 的索引方法 return
之前添加以下代码$body_class = '';
if (isset($args['route'])) {
$route = (string)$args['route'];
if ( $route == 'common/login' )
$body_class = 'login-background';
}
$data['body_class'] = $body_class;
传递参数给common/header,在admin\controller\common\login修改它。php
$data['header'] = $this->load->controller('common/header', array('route' => 'common/login'));
保持common\header.tpl的正文标签如下
<body class="<?php echo $body_class; ?>">