Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter best practices with external stylesheets, scripts, includes, etc

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!

like image 856
ItsPronounced Avatar asked Sep 23 '10 21:09

ItsPronounced


3 Answers

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" />
like image 71
Johnny Tops Avatar answered Oct 31 '22 15:10

Johnny Tops


What I did for including external files is the following :

  • Edit the .htaccess in the root directory
  • 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 ...

like image 29
Marcandria Avatar answered Oct 31 '22 15:10

Marcandria


Take a look in this library: carabiner. Its a good way to manage your assets groups

like image 2
AdrZ Avatar answered Oct 31 '22 15:10

AdrZ