duanlu8613 2015-10-08 13:59
浏览 278
已采纳

如何在登录页面上设置背景图像(opencart 2.0.x)

I'm running opencart 2.0.3.1 and i wanted to add a responsive background image on the admin login page (route: common/login ). i thought on doing so by editing the header.tpl file on /admin/view/template/common and adding a php condition on the body tag where i add a class with the background if the route = "common/login".

My logic thinking: first i want to test if there's a route (so if !landing page), if there's one then check if it equals the login route and if so, insert the "background-image" class on the tag.

here's my php code:

  <?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"'); 
       } 
 } 
?>

Here's my header.tpl's body tag:

   <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"'); 
           }
        }
     ?>
>

and here's my 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;
}

but i get this error:

Notice: Undefined index: route in "MYDIRECTORY"/vqmod/vqcache/vq2-admin_view_template_common_header.tpl on line 39

If i'm not mistaken the problem is on the "2nd if" but i don't know how to solve it (I'm still a n00b as you can see.)

Hope you can help me out!!

  • 写回答

1条回答 默认 最新

  • dougai2427 2015-10-08 14:47
    关注

    First, add below code on admin\controller\common\header.php's index method before 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;
    

    Second, modifiy the body tag on admin\view\template\common\header.tpl as below

        <body class="<?php echo $body_class; ?>">
    

    ==================================================================

    Update:

    Sorry my fault, the $this->request->get['route'] cannot access by common\header.php. This is the updated method tested on opencart 2.0.2.0:

    Add argument on admin\controller\common\header.php

    public function index($args) {
    

    Add below code on admin\controller\common\header.php's index method before return

    $body_class = '';
    if (isset($args['route'])) {
        $route = (string)$args['route'];
        if ( $route == 'common/login' )
            $body_class = 'login-background';
    }
    $data['body_class'] = $body_class;
    

    Pass parameter to common/header, modify it on admin\controller\common\login.php

    $data['header'] = $this->load->controller('common/header', array('route' => 'common/login'));
    

    Keep common\header.tpl's body tag as below

    <body class="<?php echo $body_class; ?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。