注:確保您已設置自己的基本網址在config.php這是一個必須做的CodeIgniter
$config['base_url'] = 'http://localhost/projectname/';
3個版本或直播域有點像
$config['base_url'] = 'http://www.example.com/';
確保你的CSS,JS,圖片等都是出來的應用程序文件夾的一面。如果你在應用程序文件夾中有它,它將被阻止。
application
assets
assets > css > bootstrap.css
assets > js > bootstrap.js
assets > images
system
index.php
自動載入url helper中的config/autoload.php
自動加載傭工和庫等都是很好的,你可以自動加載你認爲那些你會使用定期
示例性負載使用base_url()
在你的頭部區域,你可以花邊
<head>
// Meta
// Title
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/bootstrap.css');?>"/>
<!-- Load jQuery.js file before your bootstrap.js -->
<script type="text/javascript" src="<?php echo base_url('assets/js/bootstrap.js');?>"></script>
<!-- you can place the boostrap js on the body if you want as they say but i place in head. -->
</head>
控制器
<?php
class Example extends CI_Controller {
public function index() {
$this->load->view('header');
$this->load->view('content');
$this->load->view('footer');
}
}
我不知道,如果這是你之後,但不知道你爲什麼會想這樣做。
<head>
// Meta
// Title
<?php $this->load->view('css');?>
</head>
[CodeIgniter PHP樣式錶鏈接可能重複。如何?](http://stackoverflow.com/questions/2745153/codeigniter-php-stylesheet-link-how) – hassan
希望我的答案幫助http://stackoverflow.com/questions/42549892/how-to-include-css -file-in-codeigniter/42550927#42550927 – user4419336