php 如何在 CodeIgniter 中包含 CSS 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14008832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I include the CSS file in CodeIgniter?
提问by user1814971
I have make a assets folder in root directory where application folder exist. now I have assets sibling to application.
我在应用程序文件夹所在的根目录中创建了一个资产文件夹。现在我有应用程序的同级资产。
Now when I tried to open http://localhost/CodeIgniter/assets/css/bootstrap.min.cssin web-page it's not working.
现在,当我尝试http://localhost/CodeIgniter/assets/css/bootstrap.min.css在网页中打开时,它不起作用。
Do someone can help me how I can got it worked.
有人可以帮助我如何让它发挥作用。
In a solution I found that writing this line in config file will work but it's not work either by doing this change.
在一个解决方案中,我发现在配置文件中写入这一行会起作用,但通过进行此更改也不起作用。
$config['base_url'] = 'http://localhost/CodeIgniter/';
Now please some guideline me how to load CSS file in CI.
现在请指导我如何在 CI 中加载 CSS 文件。
solution :-
解决方案 :-
I have done something wrong in my codeigniter project. I download it again and try these thing again, without anything it's working.
我在我的 codeigniter 项目中做错了什么。我再次下载并再次尝试这些东西,但没有任何效果。
thanks you all of guys. you save my time.
谢谢大家。你节省了我的时间。
采纳答案by Sibiraj PR
define general css that used. Open "config.php" within directory CodeIgniter\system\application\config.
定义使用的通用 css。在 CodeIgniter\system\application\config 目录中打开“config.php”。
$config['css'] = 'mystyles.css';
Create a file named mystyles.css within root application: \CodeIgniter.
在根应用程序中创建一个名为 mystyles.css 的文件:\CodeIgniter。
$this->load->helper('url');
$data['css'] = $this->config->item('css');
You can load css in views pages like this.
您可以在这样的视图页面中加载 css。
回答by alditis
In constant.php:
在constant.php中:
define('URL','http://localhost/CodeIgniter/');
define('IMG',URL.'assets/img/');
define('CSS',URL.'assets/css/');
define('JS',URL.'assets/js/');
In config.php:
在 config.php 中:
$config['base_url'] = URL;
In view:
鉴于:
<link rel="stylesheet" href="<?php echo(CSS.'bootstrap.min.css'); ?>">
Hope that helps somewhat.
希望有所帮助。
回答by Gampesh
Add below line in your controller action /application/controllers/yourController.php
在您的控制器操作 /application/controllers/yourController.php 中添加以下行
$this->load->helper('url');
Then add below line to your view file's head tag.
然后将下面的行添加到您的视图文件的 head 标记中。
<link rel="stylesheet" type="text/css" href="<? echo base_url('assets/css/yourcssfile.css');?>" />
Assuming that you have assets/css/ folder is created in your app directory.
假设您在应用程序目录中创建了 assets/css/ 文件夹。
<path to your app folder>/assets/css

