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?
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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With