1

I am newer in CI. So I don't know how to load CSS and JS. I google it but do not success

CI Code

<?php echo base_url(); ?>
<link href="<?php echo base_url()."css/bootstrap-cerulean.css"?>" type="text/css" rel="stylesheet">

enter image description here

This is my directory structure. Need any configuration for it and it path display in browser like below but it not loaded css.

http://localhost/codeIgniter/css/bootstrap-cerulean.css

Required any help please comment I will help further if needed.

8
  • Your assets (images, scripts, and style sheets) aren't supposed to be in the application directory as it is not accessible. Commented Jul 15, 2014 at 4:59
  • possible duplicate of how to load css file in codeigniter (out of other infinite duplicates) Commented Jul 15, 2014 at 5:01
  • @nightgaunt I will try all that but not success as I mentioned in question so My question is any configuration needed for that or other setting has doing? Commented Jul 15, 2014 at 5:03
  • you'll find an .htaccess file in applications folder which makes it not accessible. either move it to assets as said by kemal else write an htaccwss Allow from all and put it in those 3 folders. Commented Jul 15, 2014 at 5:03
  • @karanthakkar Can you help me where to put and what you write in .htaccess file? Commented Jul 15, 2014 at 5:04

2 Answers 2

2

Put your css/js/images/etc folders in your root directory. In this way you can add css or any assets to your site. As simple as that.

<?php echo base_url("css/style.css"); ?>

UPDATE: Make sure .htaccess file allows access to these folders.

Sign up to request clarification or add additional context in comments.

6 Comments

I mentioned my directory structure can you tell me where I put?
to your root folder.. Where your index.php is located.
root folder usually have application & system folders as well by default, if you have not specified it in your index.php file.
Where is my root folder. index.php in application folder
there is no index.php in any other folder except for the main(or first or top most) folder when you download CodeIgniter. When you extract the archive you downloaded CI. The top most level folder is your root directory
|
1

keep out your css and js, images on root dir not in application then try

<?php echo base_url("css/style.css"); ?>

else you need to

<?php echo base_url("application/css/style.css"); ?>

1 Comment

Thanks I moved css/js from application folder to codeigniter folder now It works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.