Welcome Guest, Not a member yet? Register   Sign In
So your CSS or Javascript file isn't loading?
#1

[eluser]Aken[/eluser]
It shocks me that so many people who are attempting to program in PHP cannot solve this on their own.

In my opinion, if you cannot solve this, or even worse, realize why the problem is happening in the first place, you should NOT be using Codeigniter yet! Frankly it is out of your league!

The Problem

You are trying to load a CSS, Javascript or similar file, but you are loading it from the wrong location. 99% of the time this is caused by trying to load asset files using relative URLs. Here's an example:

Code:
<link rel="stylesheet" href="css/mysite.css">

Relative URLs are essentially added on to the end of the current URL you are looking at (check the location bar of your web browser). That means, if you're on your homepage, it might work, but once you go somewhere else, it won't.

Code:
'http://example.com' => 'http://example.com/css/mysite.css'
'http://example.com/subfolder' => 'http://example.com/subfolder/css/mysite.css'

The Solution - Stop using relative URLs!

The most simple way to debug this problem is:

1) Find the URL that is attempting to be loaded.
2) Find out what's wrong with it.
3) Fix it.

Here are a couple suggestions for avoid this:

Use absolute URLs.
Code:
<link rel="stylesheet" href="/css/mysite.css">
The first slash means "start from root directory" essentially. If you have your site in a subfolder, this may be problematic. In which case, try...

Use base_url()
Code:
<link rel="stylesheet" href="<?php echo base_url('css/mysite.css'); ?>">
// OR
<link rel="stylesheet" href="<?php echo base_url(); ?>css/mysite.css">

The base_url() function comes from the URL helper (make sure you load it if you use this function). It uses whatever you set as your base URL in your main config file (or what is automatically generated by CI if you leave it empty).

Relative URLs are a problem that can cause bugs in MANY places of your application, not just for loading assets like these. Ajax URLs are a big common example of this. So learn how these URLs work before you frustrate yourself, and clog up forums with such a trivial problem.
#2

[eluser]InsiteFX[/eluser]
For relative paths add this in the header section!
Code:
<head>
    <base href="<?php echo base_url();?>" />
</head>




Theme © iAndrew 2016 - Forum software by © MyBB