【发布时间】:2016-11-07 23:04:39
【问题描述】:
$config['base_url'] = 'localhost/project';
<link href="<?= base_url(); ?>/css/bootstrap.min.css" rel="stylesheet">
会产生错误,并且由于双“/”,它不会在我的视图上加载我的 CSS。
这是浏览器上视图的页面源。
<link href="localhost/project//css/bootstrap.min.css" rel="stylesheet">
CSS 不会加载。当我尝试页面源并点击链接时,它会导致 404 错误。
我感到困惑的是,当我在配置文件的 base_url 上添加协议时。
<link href="http://localhost/project//css/bootstrap.min.css" rel="stylesheet">
由于未知的原因,上面的 url 似乎指向 css,它加载到我的视图中,即使它在 'project' 和 'css' 之间的 url 上仍然有双 '/'。此外,即使我在视图上的“css”之前删除了“/”,它也会加载,只要我在我的基本 url 上添加一个协议,即使没有协议,即使没有双 '/',它仍然会成功' t 加载 css。
<link href="http://localhost/project/css/bootstrap.min.css" rel="stylesheet">
我也有一些问题,
在我上面的配置基本 url 上,我从来没有在末尾添加一个“/”,那么为什么当我在视图上使用函数 base_url 时它会添加一个“/”。为什么会这样?
我的第二个问题是我的网址上的“/”。
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="/css/shop-homepage.css" rel="stylesheet">
在我的浏览器上单击视图页面源上的 url 时的第一个链接,它仍然在 url 中有控制器。
http://localhost/project/Pages/css/bootstrap.min.css
如果我在“css”之前添加一个“/”,它会删除 url 中的“项目”和“页面”。
http://localhost/css/shop-homepage.css
我可以解决问题,只是我不知道它们为什么会发生,所以即使我可以让我的 css 加载但我感觉不对,因为我不知道为什么。
【问题讨论】:
标签: php html css codeigniter