Codeigniter – Placing of css in codeigniter views

codeigniterviews

I am new to codeigniter. I made a simple controller to load the three views: header, body and footer. My header contains links to several javascripts and CSS which have a relative paths. I kept all the css and js relative to file in views folder.

The problem is that the controller loads everything properly but images, js and css are not getting loaded.

This is the hierarchy of my view:

CSS(sub directory in views)
JS (sub directory in views)

header (header view file)
body (body view file)
footer (footer view file)

ny idea?

Best Answer

It is not a good idea to put everything in your view file, as those folders are supposed to clean things up, putting them in view makes them messy again.

Assume this is your directories:

Localhost

  • Application
    • Controllers
    • Views
    • Etc..
  • System
  • Assets
    • Javascripts
    • CSS

To include any of javascripts, the path would be:

localhost/Assets/Javascripts/your_script.js

and obviously CSS would be

localhost/Assets/CSS/your_stylesheet.css

In order to make sure your implementation work everywhere,

<script src="<?=base_url('path/to/your/js/foo.js')>" type="text/javascript"></script>

would be the safest way

Related Topic