Welcome Guest, Not a member yet? Register   Sign In
Simple Question - Where am I suppose to put External CSS and Images
#1

[eluser]tfliam[/eluser]
Hi, just wondering, where am I suppose to put all the External CSS, javascripts and Images ?

Is it under 'Views' folder ? Because I can't seem to access them directly.
#2

[eluser]Michael Wales[/eluser]
Anywhere you want - and use base_url() to setup a absolute URL to the file. There are various other ways but I find this the easiest.

A quick search of the forums will reveal hundreds of topics concerning this.
#3

[eluser]Référencement Google[/eluser]
I have done a screencast some time ago. Unfortunally the sound quality is really not good, but it will help you understand where to put your assets in a CodeIgniter application, look it following this link:

http://www.codeigniterdirectory.com/comp...Itemid,10/
#4

[eluser]dameryworld[/eluser]
An example always helps:
For example you have a view file called site_view.php located in
codeigniter/system/application/views/ folder.
to use an external css file called site.css
put the file in the same folder location
codeigniter/system/application/views/
then in your site_view.php file reference it by using the previous mentioned base_url() function.
as seen below:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>system/application/views/site.css" />

*Note: At least it works for me. Hope this helps.
#5

[eluser]Référencement Google[/eluser]
I would advice that you place your assets outside of the system folder (a "public" folder for example)
#6

[eluser]Colin Williams[/eluser]
CI doesn't rewrite how Apache works. If you put a file at /web-root/images/image.gif, you can access that image with http://www.example.com/images/image.gif (or src="/images/image.gif", href="/css/main.css", etc)
#7

[eluser]m4rw3r[/eluser]
Just remember that your .htaccess must not redirect those requests for the assets to CI.

And as stated before in this thread, do not put the assets in the system or application directory (you may want to move system and application out of the webroot or rename them).
Put them in a separate dir next to index.php, and use base_url() + 'dirname/file.png' to get the address.
#8

[eluser]dameryworld[/eluser]
I am new to the whole MVC framework coding paradigm but I would think the css is an asset to the view and would need to be kept close to the file using it....maybe I should think of this as MVCA keeping Models Views Controllers and Assets in their own groups?
*Note: The reason I wanted to put the css in the same folder as the view was in case I did move the view I wanted to keep associated css with it.
#9

[eluser]wiredesignz[/eluser]
Actually the View and the css are totally unrelated.

Any properly coded view can be restyled.

css is a (site) theme related component and should be located somewhere available to the browser.
#10

[eluser]dameryworld[/eluser]
Ah, I get it. Like I said this is a new paradigm...I am still learning to break my ideas into MVC parts. Thanks for hanging with my slow paradigm shifting...




Theme © iAndrew 2016 - Forum software by © MyBB