Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS文件未加载到我的CodeIgniter PHP中_Php_Codeigniter_Autoload_Base Url - Fatal编程技术网

CSS文件未加载到我的CodeIgniter PHP中

CSS文件未加载到我的CodeIgniter PHP中,php,codeigniter,autoload,base-url,Php,Codeigniter,Autoload,Base Url,我对Codeigniter是新手。我试图加载css文件,但失败了。我搜索它谷歌应用所有的解决方案,但它不工作 我还对mu自动加载文件进行了更改 $autoload['helper'] = array('url', 'form'); 这是我的控制器代码,名为Login.php <?php class Login extends CI_Controller{ function index(){ $this->load->helper

我对Codeigniter是新手。我试图加载css文件,但失败了。我搜索它谷歌应用所有的解决方案,但它不工作

我还对mu
自动加载文件进行了更改

$autoload['helper'] = array('url', 'form');
这是我的控制器代码,名为Login.php

<?php
    class Login extends CI_Controller{
        function index(){
            $this->load->helper('url'); 
            $this->load->helper('html');
            $data['main_content'] = 'login_form';
            $this->load->view('include/template', $data);
        }
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel = "stylesheet" type = "text/css" href = "<?php echo base_url();?>css/style.css">
<title>Untitled Document</title>
</head>

<body>
    <div id="login_form">
        <h1>Login Page..!!</h1>
        <?php
        echo form_open('login/validate_credentials');
        echo form_input('username', 'Username');
        echo form_password('password', 'Password');
        echo form_submit ('submit', 'Login');
        ?>

    </div>
</body>
</html>

假设您的
base\u url()
是域的根(例如
http://localhost
),然后它将返回应用程序的根目录(存储CodeIgniter的
index.php
的目录)。因此,您所要做的就是将
css
文件夹移动到该目录。我相信这比您的
css
文件夹的当前位置提高了一步

还请注意,您必须在CodeIgniter
config.php
文件中设置base_url(),如下所示:

$config['base_url'] = 'http://localhost';
试试这个:

<link rel = "stylesheet" type = "text/css" href = "<?php echo base_url();?>application/css/style.css">

在网页上单击鼠标右键并选择“检查”,打开浏览器控制台

转到网络请求/控制台,检查链接文件(CSS)的URL


如果您发现应用程序中给定的路径不同,则需要相应地更改代码以获得适当的路径。

解决了您的问题将css文件夹移出应用程序文件夹,并放置在根结构上。

->application
->css

首先维护您的文件夹结构下载CodIgniter并从新结构开始

如果可以使用CI版本3,请在配置文件中设置基本url

设置项目文件夹名称

$config['base_url']=''

使用base_url()加载css:通常我们使用bae_url()加载js、css和图像

 <link rel = "stylesheet" type = "text/css" href = "<?php echo base_url();?>css/style.css">

检查浏览器控制台是否有任何错误。。并告诉我们错误。@ShaktiPhartiyal我怎么做?右键单击页面并单击inspect@ShaktiPhartiyal谢谢,伙计,我发现了我的错误。实际上,我把css文件夹放在应用程序文件夹中,它需要放在应用程序文件夹之外:):)谢谢Man@sunny我已经补充了答案。。
 <link rel = "stylesheet" type = "text/css" href = "<?php echo base_url();?>css/style.css">