Where is it acceptable to put css folders and image file folders? I was thinking inside the view folder? However the controller always reroutes the path to the base url so I have to specify the path in the .html file to where it sits, which is redundant.
相关问题
- Can you set the Location header in a chunked http
- How to use strip_tags with second parameter in Cod
- codeigniter replace array values in model
- How to access variables from other methods inside
- codeigniter $this->upload->do_upload() = false
相关文章
- Private static variables in php class
- File Upload of more than 4GB
- Returning plain text or other arbitary file in ASP
- GuzzleHttp Hangs When Using Localhost
- Codeigniter not logging
- Swift and Objective-c framework exposes its intern
- Loading custom config file into a Codeigniter libr
- Loading and using a codeigniter model from another
No, inside the views folder is not good.
Look: You must have 3 basic folders on your project:
system // This is CI framework there are not much reasons to touch this files
application //this is where your logic goes, the files that makes the application,
public // this must be your documentroot
For security reasons its better to keep your framework and the application outside your documentroot,(public_html, htdocs, public, www... etc)
Inside your public folder, you should put your public info, what the browsers can see, its common to find the folders: images, js, css; so your structure will be:
I'm using the latest version of CodeIgniter 3.1.0. The folder structure of it is:
That's where you should put the images, css and js files inside the assets folder.
The
link_tag()
helper is clearly the way to do this. Put your css where it usually belongs, in site_root/css/ and then use the helper:From The CodeIgniter docs...
Output
I have a setup like this:
I then have a helper function that simply returns the full path to this depending on my setup, something similar to:
application/helpers/utility_helper.php:
I will usually keep common routines similar to this in the same file and autoload it with codeigniter's autoload configuration.
application/config/autoload.php:
You will then have access to
asset_url()
throughout your code.Regardless of where you put the CSS file you can simply use the CodeIgniter "html" helper called link_tag(). You would apply this helper something like this:
It is up to you to locate the CSS file in the most appropriate place (in your opinion). You would have to either autoload the "html" helper or separately load it in to use it.
People keep suggesting the usage of base_url() to achieve this but it is actually not really the "CodeIgniter" way to do it (I think this question has a few duplicates). That will work but one of the reasons for using a framework is to use the pre-made functions within it.
There are many helpers in codeigniter to do this kind of thing.
No one says that you need to modify the .htacces and add the directory in the rewrite condition. I've created a directory "public" in the root directory alongside with "system", "application", "index.php". and edited the .htaccess file like this:
Now you have to just call
<?php echo base_url()."/public/yourdirectory/yuorfile";?>
You can add subdirectory inside "public" dir as you like.