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 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题
  • ¥20 materialstudio计算氢键脚本问题
  • ¥15 有没有代做有偿主要做数据可视化部分即可(2023全国高考更省一本线理科类)