Ok so I've been studying Codeigniter and PHP for a week or so now and I'm ready to begin my first site. I'm wondering what are best practices for handling files that aren't Models, Views, or Controllers? Such as includes, stylesheets, javascript files (like my jQuery), etc...
From the tutorials I read, I've developed a habit of taking my Application folder and moving it up one directory to be in the same folder as my System and User Guide (which I'll probably delete User Guide before going live of course). Now with includes (headers and footers) I've noticed some developers make a subdir in the Views folder, usually called Globals, and put them there. What about javascript and css files? Do I need to put them in subfolders of the APPPATH and make constants for their location?
I'm trying to plan ahead. Thank you as always!
I'm not sure if there really is a best practice for where to locate your files. I follow the practice of making a subfolder in views for the template documents (header, footer, template, etc.) and then I typically put the styling and js at the root level (I have the folders application, css, images, js, and system)
I personally think it looks a bit cleaner to do it this way.
<link rel="stylesheet" href="<?php echo base_url();?>css/style.css" type="text/css" media="screen" />
IMO is a bit easier to read and maintain than
<link rel="stylesheet" href="<?php echo base_url();?>application/views/globals/css/style.css" type="text/css" media="screen" />
What I did for including external files is the following :
Locate this line, all the URLs not in the mask are rewritten :
RewriteCond $1 !^(index.php|images|scripts|assets/|robots.txt)
Then create your directories at the root and include them directly from your views like with any PHP script.
I don't know though if this is best practice ...
Take a look in this library: carabiner. Its a good way to manage your assets groups
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With