CodeIgniter Forums
Where to place resources? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Where to place resources? (/showthread.php?tid=3768)



Where to place resources? - El Forum - 10-21-2007

[eluser]lszanto[/eluser]
This may sound dumb but I can't work out where I should place my images and stylesheets so that I can access them from the views file when the page is executed and complied.
Any help is appreciated and thanks in advance.


Where to place resources? - El Forum - 10-21-2007

[eluser]nmweb[/eluser]
I put them in an asset folder at the same level of the index.php file. I then put in a <base href="base.com"/> to get all relative urls right and stuff.


Where to place resources? - El Forum - 10-21-2007

[eluser]Armchair Samurai[/eluser]
I set up my apps like this, keeping images and stylesheets in the docroot like a normal webpage:
Code:
|- app
|
|- codeigniter1.5.4
|
|- httpdocs
|   |
|   |- css
|   |
|   |- images
|   |
|   |- index.php
When you want to access a stylesheet or image, just call base_url().
Code:
<!-- In a view -->
<link href="<?=base_url();?>css/your_stylesheet.css" rel="stylesheet" type~"text/css" />

<img src="&lt;?=base_url();?&gt;images/your_image.png" alt="" />



Where to place resources? - El Forum - 10-21-2007

[eluser]danoph[/eluser]
I wrote an article on this a while ago called . If you want to remove index.php from your URI with routing and also use a .htaccess file, things get a little tricky and my article explains how to remove index.php while still allowing access to your images, css, javascript folders, etc..

Build Your First Web2.0 App with PHP, Ajax, and CodeIgniter


Where to place resources? - El Forum - 10-21-2007

[eluser]Michael Wales[/eluser]
I create the following folders at the root level:
css
js
images

I then link to those items using base_url() so I have absolute links, you could always just use a relative from root.

Absolute:
Code:
<img src="&lt;?= base_url(); ?&gt;images/home.png" />

Relative:
Code:
<img src="/images/home.png" />