我在配置中的基本 url 是:$config['base_url'] = 'http://localhost/ci/';
我的 CSS 文件夹在根级别(所以 ci)。
在我试过的 View 中:
<head>
<style> @import url('<?=base_url()?>/css/styles.css'); </style>
</head>
和
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url()?>css/styles.css">
</head>
都失败了。使用 Codeigniter 框架导入 CSS 文件的正确方法是什么
这是我的 .htaccess 文件的样子:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
最佳答案
我使用这种方法:
文件夹结构:
example.com
|_ 申请
|_ Assets
|_ 系统
CI 2.x
我已经设置了$config['base_url'] = '';
,这将适用于本地服务器和生产服务器
CI 3.x
警告:您必须设置此 ($config['base_url']
) 值!所以我使用下面的代码来区分本地服务器和生产服务器:
if ($_SERVER["HTTP_HOST"]=='ex.ample')
$config['base_url'] = 'http://ex.ample/';
else
$config['base_url'] = 'http://example.com/';
(我在本地服务器上使用了一个名为 ex.ample
的虚拟主机,请根据您的需要进行更改)
在我的文件夹 Assets 中,我存储 assets/css/style.css
并在我看来调用它:
<link rel="stylesheet" type="text/css" href="/assets/css/style.css" />
关于php - 在 codeigniter View 中加载 CSS 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46777194/