How to solve the problem of a path to css and images in Codeigniter

If you have a problem with linking to your css and images in view file, this may help you.

Firstly you need to check your applications/config/config.php and make it sure you have a proper path in your Base Site URL.

$config['base_url']= “http://127.0.0.1/ci/”;

Then go to your view file and add followings in the head.

<link href=”<?= base_url();?>css/your_style.css” rel=”stylesheet” type=”text/css” />
<base href=”<?=base_url();?>”>

Change your_style.css to your css name and save it in the css folder which is the same level as the system folder.
The first one should link to your css file.
And the second one is for your image file. If you have to save an image in your databse, this will be very handy.

<img id=”logo” src=”images/logo.png” />

However if you are adding images directly to your view file, then the following will be ok as well.
Then take out <base href=”<?=base_url();?>”> in the head, and use the following for each image.

<img id=”logo” src=”<?=base_url()?>images/logo.png” />

2 comments to How to solve the problem of a path to css and images in Codeigniter

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>