2014-10-16 144 views
0

我已經搜索了並嘗試了許多解決方案,爲別人工作,但不是在我的情況。我不知道爲什麼。爲什麼CSS和JS沒有加載?

背景:

我正在學習用笨2.2.0。我已經建立了項目結構和所有的東西,但我仍然無法加載我的CSS和JS。

查看代碼:

<!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 id="Head1"> 
     <title> </title> 
     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
     <!-- solution 1 I have tried: --> 
     <!-- in below line I tried by using constant set in constants.php file under application/config/ folder --> 
     <link rel="stylesheet" href="<?php echo (CSS.'dialog.css');?>" type="text/css"> 
     <!-- solution 2 I have tried: --> 
     <!-- As my css n script files are under CodeIgniter_2.2.0/assets/css and CodeIgniter_2.2.0/assets/scripts folder respectively --> 
     <link rel="stylesheet" href="/assets/css/dialog.css" type="text/css"> 
     <!-- solution 3 I have tried --> 
     <!-- This I tried by using autoload.php settings where I am setting autoload['helper'] = array('url'); --> 
     <?php echo link_tag('assets/css/dailog.css');?> </br> 
     <script src="../../script/Plugins/jquery.js" type="text/javascript"></script> 
    </head> 
</html> 

配置

而且我已經在application/config/config.php文件中設置

$config['base_url'] = "http://localhost/";

項目文件夾結構:

我的項目文件夾結構如下:

enter image description here

(應用程序,系統,資產文件夾是在同一級別)

的內容.htaccess文件是:

(.htaccess文件路徑:C:\ XAMPP \ htdocs.htaccess)

RewriteEngine on 

RewriteCond $1 !^(index\.php|images|js|css|robots\.txt) 

RewriteRule ^(.*)$ /index.php/$1 [L] 

有在C:\xampp\htdocs\CodeIgniter_2.2.0\System 2更.htaccess文件和文件夾C:\xampp\htdocs\CodeIgniter_2.2.0\application既 有單行寫入:

Deny from all 

此外,在C:\xampp\htdocs\,有一個文件index.php,它與index.php文件放置在 C:\xampp\htdocs\CodeIgniter_2.2.0\相同,其中我已設置以下東西

$system_path = 'CodeIgniter_2.2.0/system'; 
$application_folder = 'CodeIgniter_2.2.0/application'; 

有什麼,我在這裏失蹤?我無法在我的頁面上加載任何CSS或JS文件。

+0

這可能是相關的一個實例您的CSS文件被命名爲'對話框,然後其他兩個實例是'dailog'?這應該是相同的文件,或者你有多個CSS文件嗎? – TylerH 2014-10-16 17:39:41

+0

我已經回答了一個可能對您有用的問題:http://stackoverflow.com/questions/19201362/codeigniter-unable-to-access-the-stylesheets/19204480#19204480 – grim 2014-10-18 16:46:18

+0

您在瀏覽器中收到什麼信息爲你正在加載的文件? 404?你也可以展示你在HTML中返回的三個嘗試解決方案嗎? – grim 2014-10-18 16:48:32

回答

1

這裏是解決方案:就在根目錄

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php/$1 [QSA,L] 

ň其工作作出.htaccess變化。 :)