How to load CSS into CodeIgniter
Tags: css,codeigniter
Problem :
I am totally new in CodeIgnitor. In the controllers folder I created a file named caller.php
and I created a file home.php
in views. In views I also created a folder named css
and I created style.css
in that css
folder. In views I have some pictures. Those pictures are also part of design. Now I want to use style.css
and the pictures. But I can't.
In caller.php I have:
class caller extends CI_Controller
{
function index()
{
$this->load->view('home');
// What do I have to write here to load css?
}
}
In home.php I have:
<html>
<head>
***------what i have to write here to load css--------***
</head>
<body>
<div id="outer">
...
</div>
</body>
</html>
If additional configs are needed please mention that.
Solution :
Leading on from what Oliver said of including the stylesheet with:
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">
If you have removed index.php from your URL's make sure you include your css directory in the rewrite rule.
RewriteEngine on
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ /index.php/$1 [L]
This is assuming your stylesheet is located in a folder called css
at the root of your application.
- index.php
+ system
+ application
+ css
- style.css
Make sure that you have enabled the URL helper to use commands such as base_url()
. This can be done globally inside config/autoload.php
by adding url to the helper array.
$autoload['helper'] = array('url');