Welcome Guest, Not a member yet? Register   Sign In
Lost all CSS styling when changed to index.php
#1

[eluser]CoderReborn[/eluser]
Hi, there,

I'm new to Code Ignitor and have run into the following frustrating problem:

I have an existing index.html file with an external CSS file that works fine.

I want to rename "index.html" to "index.php" for a number of reasons.
I'll be using it as a View.
So, my views folder includes:
- index.php
- css folder
- js folder
- images folder

However, when I rename the file, all CSS styling is lost!
There is currently no PHP code in this file, yet. It's all HTML.
Here are the first few lines of "index.php".

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
    &lt;head&gt;
        &lt;title&gt;Title &lt;/title&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
        &lt;link rel="stylesheet" type="text/css" href="css/all.css" /&gt;

Thanks for your help!
#2

[eluser]Clifford James[/eluser]
Try this:

&lt;link rel="stylesheet" type="text/css" href="/css/all.css" /&gt; Note the first /
#3

[eluser]LuckyFella73[/eluser]
I recommend you to place your css folder inside your root folder!
then you can use
Code:
base_url()
to build your pathes.

In your example:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
    &lt;head&gt;
        &lt;title&gt;Title &lt;/title&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
        &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo(base_url());?&gt;css/all.css" /&gt;
#4

[eluser]CoderReborn[/eluser]
Thank you for all your help!
I did the following and it worked!

1) Moved my css, js, and images folders to my root (which is also my "base_url")

2) Added the following &lt;base&gt; tag to my index.php view file:

Code:
&lt;base href="&lt;?php echo base_url(); ?&gt;" /&gt;

All of my links are now relative to this base_url.

3) Loaded the URL helper in my controller (so my view file can access the base_url() function).

Code:
$this->load->helper('url');

It's all good now. Thanks again.
#5

[eluser]nelson.wells[/eluser]
Have you considered using an assets library or helper? They simplify things sooo much, and isn't that why we're using CI in the first place? Smile
#6

[eluser]CoderReborn[/eluser]
@Nelson.wells: I am using the URL helper. Any other helper you'd recommend for this?

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB