如何在codeigniter 3中设置背景图像

新手上路,请多包涵

几天前我开始使用codeigniter,我无法通过css文件设置背景图像。我的控制器(verifylogin.php)是这样的:

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class VerifyLogin extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('user','',TRUE);
   $this->load->helper('url');
 }

 function index()
 {
   //This method will have the credentials validation
   $this->load->library('form_validation');

   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

   if($this->form_validation->run() == FALSE)
   {
     //Field validation failed.  User redirected to login page
     $this->load->view('login_view');
   }
   else
   {
     //Go to private area
     redirect('home', 'refresh');
   }

 }

 function check_database($password)
 {
   //Field validation succeeded.  Validate against database
   $username = $this->input->post('username');

   //query the database
   $result = $this->user->login($username, $password);

   if($result)
   {
     $sess_array = array();
     foreach($result as $row)
     {
       $sess_array = array(
         'id' => $row->id,
         'username' => $row->username
       );
       $this->session->set_userdata('logged_in', $sess_array);
     }
     return TRUE;
   }
   else
   {
     $this->form_validation->set_message('check_database', 'Invalid username or password');
     return false;
   }
 }
}

而视图(login_view.php)就是这个。

 <html>
 <head>
   <title>OpediaLab</title>
 </head>
 <body>
   <h1></h1>
   <?php echo validation_errors(); ?>
   <?php echo form_open('verifylogin'); ?>

<link rel="stylesheet" type="text/css" href="<?=base_url()?>style.css"/>
<label for="username">Username:</label>
     <input type="text" size="20" id="username" name="username"/>
     <br/>
     <label for="password">Password:</label>
     <input type="password" size="20" id="passowrd" name="password"/>
     <br/>
     <input type="submit" value="Login"/>
   </form>
 </body>
</html>

css 文件仅包含以下两行:

 body{
background-image: url("C:/wamp/www/CI/application/views/immagini/Opedia_LAB.png");
background-color: green;
}

现在,我很确定 css 文件必须位于特定文件夹中(我看过很多教程,但并非都说同样的话)。我所做的最后一次尝试是将文件放入“视图”中,如图所示 在此处输入图像描述

我希望我足够清楚,而且我知道,这是因为我对这个框架非常陌生。

这就是我在任何试图改变我所做的事情时所看到的。没有错误但没有css效果。

在此处输入图像描述

更新:

这是我从控制台得到的:

在此处输入图像描述

原文由 user5913892 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 657
2 个回答

尝试这个

<html>
 <head>
   <title>OpediaLab</title>
   <link rel="stylesheet" href="<?php echo base_url('style.css');?>">
 </head>
 <body>
   <h1></h1>
   <?php echo validation_errors(); ?>
   <?php echo form_open('verifylogin'); ?>

<label for="username">Username:</label>
     <input type="text" size="20" id="username" name="username"/>
     <br/>
     <label for="password">Password:</label>
     <input type="password" size="20" id="passowrd" name="password"/>
     <br/>
     <input type="submit" value="Login"/>
   </form>
 </body>
</html>

原文由 naseeba c 发布,翻译遵循 CC BY-SA 3.0 许可协议

"C:/wamp/www/CI/application/views/immagini/Opedia_LAB.png"

由于安全原因,您正在从应用程序目录中获取图像并且用户禁止使用它,因此您不能从应用程序目录中获取图像,可以做同样的方式,但图像应该在应用程序目录之外,您可以使用自己的目录,如资产。

在应用程序目录中有 htaccess 文件,它全部拒绝。

 <IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

原文由 Sorav Garg 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题