Setting up Code Igniter

February 13, 2010 | 2 Comments

A few months ago, we jumped into Teeorama, a PHP based online tee-shirt store front end for Spreadshirt. We finally completed the project and we’re planning on opening it to the public tomorrow. By the way, if you feel you could use a new Geek shirt, please head over to teeorama.com before reading on…

When I started the development, I decided to use both a PHP and a Javascript framework I didn’t know. I had two reasons for doing that:

  • It’s always interesting to play with new code. You get to see how other people/framework solved common problems, how some libraries make this or that easier  to use for the developer. You also sometimes realize some other things are carried out better in the framework you are used to. Either way, it is a good learning experience.
  • Also, I wanted to stay away from the stack we use at work to not be tempted and not be able to just copy over bits of our blueKiwi framework into my code

So, I picked CodeIgniter and jQuery to build my website. In the end, I am very pleased with the experience of working with these two tools. CodeIgniter is exactly what it claims to be: a very light but powerful framework that does not try to command the way you work. Of course, jQuery is just as powerful as its reputation. It’s incredibly easy to get used to and I haven’t found anything it couldn’t do.

Anyway, this post is about setting up Code Igniter. There is a Code Igniter user_guide (included in the downloaded zip file) to do just that and it would take you about two seconds to get going. The thing is, I did not like the way Code Igniter was laid out in my folder. I wanted to be able to place the framework in a library folder within my application folder and make my web folder (containing the images, javascript and css files) the document root therefore keeping my application folder out of exposure to the Web.

This is also possible though it does involve some minor tweaking of CodeIgniter base code.

First, here is my chosen folder layout

Second, as I said, I made the web folder the target of my Apache virtual host.
Here is my virtual host for this application

1
2
3
4
5
6
7
8
ServerAdmin your_email
ServerName project_domain
AddDefaultCharset UTF-8
DocumentRoot /var/www/project/web

RewriteEngine On
RewriteCond $1 !^/?(index\.php|test|images|web|js|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

Finally, in order for all this to work, you need to tweak a couple of CodeIgniter files

define the system and application folders paths as follow in index.php:

1
2
3
$docRootPath = dirname($_SERVER['DOCUMENT_ROOT']);
$system_folder = $docRootPath."/application/libraries/codeigniter";
$application_folder = $docRootPath."/application";

Also, modify the CodeIgniter.php file at the bottom of index.php to:

1
require_once BASEPATH.'CodeIgniter'.EXT;

Finally, edit CodeIgniter.php in order to replace all occurrences of “codeigniter/” by “” (nothing)

You should be setup. Happy coding!


Comments

2 Comments so far

  1. samantha says:

    New blog post: Setting up Code Igniter: A few months ago, we jumped into Teeorama, a PHP based online tee-shirt st… http://bit.ly/9TDxbP

  2. Samantha Halfon says:

    New blog post: Setting up Code Igniter: A few months ago, we jumped into Teeorama, a PHP based online tee-shirt st… http://bit.ly/9TDxbP

Name (required)

Email (required)

Website

Leave a Reply