Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing of css in codeigniter views

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?

like image 214
bmrinal Avatar asked Dec 16 '22 01:12

bmrinal


2 Answers

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

like image 91
Jonathan Chow Avatar answered Jan 09 '23 08:01

Jonathan Chow


You need to put the files in the base directory e.g. the one containing the application and system folders.

Try using a folder called assests.

Also make sure your are using a leading slash so e.g.

href="/assets/css/style.css"

Note this will load from base URI

e.g. example.local/assets/css/style.css

like image 38
Dale Hurley Avatar answered Jan 09 '23 07:01

Dale Hurley