簡體   English   中英

base_url()在Internet Explorer(CodeIgniter)中無法正常工作

[英]base_url() not working properly in internet explorer (CodeIgniter)

我的導航欄圖像和鏈接在CHROME中可以很好地加載,但是在INTERNET EXPLORER中加載同一頁面時,圖像不會加載,但會顯示no image圖標。 IE中的鏈接是這樣的

CodeIgniter / index.php / news / index.php / news /

而不只是

CodeIgniter / index.php / news

但是,即使使用了base_url(),IE仍可以成功加載CSS,這是我的代碼:

test.php

<head>
<base href="<?php echo base_url() ?>">
<link rel="stylesheet" type="text/css" href="public/css/main.css">
</head>
 <nav>
    <ul>

     <li><a href="index.php/news">
     <img src = "public/images/home.png" alt="Home" title="Home"/>
     </a></li>


     <li><a href="index.php/news/create">
     <img src = "public/images/create.png" alt="Create new article" title="Create new article"/>
     </a></li>

    </ul>
 </nav>

config.php

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

回答

Quote:Well Fabios建議成功了,謝謝<img src = "<?=base_url('public/images/home.png')?>" alt="Home" title="Home"/>仍然有效未來的痛苦。 感謝你的幫助!

Fabios的建議很成功,謝謝

<img src = "<?=base_url('public/images/home.png')?>" alt="Home" title="Home"/>

即使將來會很痛苦也能正常工作。 感謝你的幫助!

真正的問題是您使用的是相對路徑,例如public/images/home.png而不是/public/images/home.png ,開頭的斜杠告訴瀏覽器它應該根據您擁有的絕對路徑來檢索內容指定在$config['base_Url'] = ...而不是當前路徑(我是指您到達CodeIgniter/index.php/news並指定了相對路徑,因此才將其附加到它產生錯誤的路徑CodeIgniter/index.php/news + index.php/news/ ),因此當您在路徑的開頭添加斜杠時,它將引用絕對路徑,並且會在CodeIgniter/index.php/news

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM