我正在尝试将我自己的 CSS 文件添加到我的 Codeigniter/bootstrap 元素,但我无法成功链接 CSS 文件。这是我的代码:
<!doctype html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="<?=base_url()?>public/css/style.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<header>
jrDash
</header>
<div class="wrapper">
当它请求文件时,这是正在寻找 CSS 文件的地方
localhost/jrdash/%3C?=base_url()?%3Epublic/css/style.css
最佳答案
您的问题可能与您的 base_url() 函数有关。由于某种原因,您的浏览器未评估 PHP 函数。这可能有多种原因:
- Apache 未在您的本地环境中运行
- 文件是 .html 文件而不是 .php 文件
或其他原因。
您可以验证 PHP 是否正在运行 here .
基本上,在本地服务器上创建一个名为 phpinfo.php 的新文件,键入:
<?php
phpinfo();
?>
保存并导航到该文件。如果您获得有关 PHP 的大量详细信息,那么它正在运行。如果不是,那是你的问题。
如果它正在运行,请验证您的上述代码是否在 .php 文件中。如果 php 正在运行并且代码位于 .php 文件中,那么您发布的内容没有理由不会被评估为 PHP。
一旦你的 php 函数 base_url() 工作了,你就可以开始了。
附言在您的情况下使用 base_url 函数的最佳方法如下:
<link rel="stylesheet" href="<?=base_url('public/css/style.css')?>">
关于php - 无法将 css 文件链接到 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24766175/