2013-02-28 28 views
0

我是新來web開發(特別是在CI框架中的php)。這個問題對你來說應該是一個非常簡單的問題,但我一直在Google上搜索一個小時,但仍然找不到任何解決方案。網址來顯示圖像和連接css在codeigniter

我想顯示(在IMG文件夾logo.png)的圖像,並(在風格文件夾中的style.css),我把在目錄鏈接一個CSS文件:

enter image description here

但是,當我試圖顯示圖像和鏈接的CSS,我得到的是空白網頁。 這是我的html代碼:

<!DOCTYPE html> 
<html> 
    <head> 
     <title>My First Design</title> 
     <link href="<?php echo base_url();?>style/style.css" rel="stylesheet" type="text/css"/> 
    </head> 
    <body> 
     <h1><img src="../../img/logo.jpg" />My First Web Design</h1> 
     <p> 
     I have been working on honing, and in some cases, learning new graphical skills in the past few weeks. So, I have been       extensively watching Adobe Illustrated tutorials and working on my existing Photoshop knowledge and basically trying to      get a hang of the software beyond basic image editing and digital painting. 
     </p> 
     <p> 
     From a beginner’s point of view, the world of graphical design is quite vast… at times intimidating and there is no limit       to creative options. One could branch out into any form of graphical design… illustrations or web-design or logo &         advertising and so much more. At the same time, one does not need to limit the options to just these. 
     </p> 
    </body> 
</html> 

這是我config.php BASE_URL:$config['base_url'] = 'http://localhost/ciGlassProject/';

我已經試過像一些不同的方法:

  1. 使用SITE_URL而不是BASE_URL
  2. 鍵入URL手動
  3. 以多種方式更改$config['base_url']的值。 但是,他們都沒有工作。
+1

可以'http:// localhost/ciGlassProject/img/logo.jpg'工作嗎? – pktangyue 2013-02-28 14:31:10

+0

@pktangyue是的,對不起,我想我只是想輸入網址:D – 2013-02-28 14:44:55

+0

答案是:The base(); url不工作因爲我忘了導入幫助器($ this-> load-> helper('url')):D – 2013-02-28 14:52:48

回答

1

您可以使用它應該工作的基本URL。

<img src="http://localhost/ciGlassProject/img/logo.jpg" /> 

更好的方法是使用php來獲取您的基礎URL。這將意味着,如果你移動你的網站,你不必改變這個URL很多次,讓它運行在一個新的locion中。爲此,您可以使用簡單的PHP調用:

<img src="<?php echo base_url(); ?>img/logo.jpg" /> 
+0

感謝:D 手動url現在正在工作(我想我錯過鍵入':// '部分),但是,base_url();方法不起作用。該CSS也不工作因爲我使用base_url()。奇怪的是,當我查看我的舊項目時,與base_url()方法相關的所有內容都很好。 – 2013-02-28 14:43:50

+0

對不起,我忘了導入我的控制器的幫手。感謝您的幫助:D – 2013-02-28 14:53:13