CodeIgniter Forums
img/CSS relative path problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: img/CSS relative path problem (/thread-25732.html)



img/CSS relative path problem - El Forum - 12-22-2009

[eluser]SlimDeluxe[/eluser]
Greetings.
I have a problem with using normal HTML with relative paths for page elements like images, CSS, JS files and other.
As long as I don't specify a controller method, it works like it should be working.
So, http://sabic.si/ef.si and http://sabic.si/ef.si/home are being displayed correctly. The default method being "index", it makes no sense to me that http://sabic.si/ef.si/home/index does not work.
Can anyone explain why this is happening and how can I resolve this so I can continue using normal HTML with relative paths, and not the helper functions (img() and co.)?


img/CSS relative path problem - El Forum - 12-22-2009

[eluser]Craig A Rodway[/eluser]
This is what I do in the HEAD tag of my main template:


Code:
<base href="<?php echo $this->config->item('base_url') ?>web/" />
<link rel="stylesheet" type="text/css" media="all" href="css/style.css" />

This is my directory structure:

Code:
- index.php
- system
- web
  + css
  + img
  + js

So http://server/ci/ is the CI installation. The BASE tag sets the location to the CI installation then the web/ sub-folder. All CSS, Javascripts and images are loaded relative to that.

Example:
Code:
<img src="img/foobar.jpg" />



img/CSS relative path problem - El Forum - 12-22-2009

[eluser]SlimDeluxe[/eluser]
Hi, thanks for answering so fast.
This kind of solves the problem.
Theres just this thought in my head, that the script is now accessing the elements by kind of a longer way than it really should.
With your solution all URLs then become absolute web addresses. If you put aside the fact, that you have to enable access to these elements in .htaccess, I wonder, if this has any effect on server performance.
=)


img/CSS relative path problem - El Forum - 12-22-2009

[eluser]Craig A Rodway[/eluser]
[quote author="SlimDeluxe" date="1261533784"]Theres just this thought in my head, that the script is now accessing the elements by kind of a longer way than it really should.
With your solution all URLs then become absolute web addresses. If you put aside the fact, that you have to enable access to these elements in .htaccess, I wonder, if this has any effect on server performance.
=)[/quote]

I have no idea what you mean here.

The code I posted simply does this:

It sets the BASE tag to the path where your assets are stored. Any code that loads an asset (javascript, stylesheet, image) relatively (as in my example) is loaded relative to the URL in the BASE tag. It has no relevance to htaccess, thus having no effect on server performance.


img/CSS relative path problem - El Forum - 12-22-2009

[eluser]SlimDeluxe[/eluser]
Sorry, you were right, I forgot to remove some "base_url()" echoes from the view.

This is a really elegant solution, so thank you again.