2015-11-05 32 views
0

顯示圖像我要顯示的圖像格式視圖如何笨

<img src="<?php echo base_url('images/login.jpg'); ?> " width="90" height="40" /> 

但它不工作。 當我寫

<img src="images/login.jpg " width="90" height="40" /> 

它顯示了瀏覽器,但不顯示在本地主機

是否在我的.htaccess中的問題

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase /helloworld/ 

    # Disable rewrite for valid directory/files  
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    #map all request urls to a specific controller method 
    RewriteRule ^(.*)$ index.php?/{controller}/{method}/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

請人幫我

+0

它不起作用?它根本不顯示?你得到的任何錯誤? – Sina

+0

通過檢查元素檢查圖像是否正在加載 –

+0

它正在加載但圖像不顯示 –

回答

0

如果你只是想在你的htaccsess文件中沒有「index.php」的訪問應該是這樣的

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase /helloworld/ 

    # Disable rewrite for valid directory/files 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    #map all request urls to a specific controller method 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

而圖像文件夾必須位於項目的根目錄中。 我希望我的回答可以幫助你:d

+0

我的圖像在我的項目中的圖像文件夾在視圖文件夾 –

+0

如果你通過基地址,我認爲在這種情況下,你必須使用靜態url,如: 因爲當你使用base_url(「'images/login.jpg'」)時,圖片的src url是「http:localhost/images/login.jpg」和它必須位於根目錄下的images文件夾中。 – LostOdyssey

0

無論.htaccess文件的這種方法,把index.php

<img src="<?php echo base_url('index.php/images/login.jpg'); ?> " width="90" height="40" /> 

但是,如果你仍然想使用.htaccess文件,然後替換所有代碼.htaccess文件與此代碼:

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

然後你就可以在不index.php

訪問
<img src="<?php echo base_url('images/login.jpg'); ?> " width="90" height="40" /> 
+0

我嘗試了兩種解決方案,但圖像不顯示 –

0

做這樣

<img src="<?php echo base_url(); ?>images/login.jpg" width="90" height="40" /> 

以及在config/config.php

$config['base_url'] = ''; 

和你的形象應該是地方一個

application 
images 
    login.jpg 
system 
index.php 
+0

這是我的config.php $ config ['base_url'] ='http:// localhost/helloworld /'; –

+0

刪除它。只是保持空 –

+0

@ A.Nabil發生了什麼? –

0

你有與廣告相關的任何類名?? 如果是的話,瀏覽器的廣告代碼塊擴展往往會隱藏圖像,在我的項目中也面臨類似的問題,只是禁用測試的擴展名或更改類名稱。

只是一個猜測。希望它可以幫助你。

+0

你應該問問題作爲評論。 –

0

不要忘記在你的控制器構造函數中導入url助手。

function __construct() 
{ 
    parent::__construct(); 
    $this->load->helper('url'); 
} 
+0

我加載了helper url –