Coding with Jesse

Code Igniter

May 14th, 2006

I'm absolutely in love. While I bored was at JAX, I searched around for a PHP framework like Ruby on Rails. I already knew about CakePHP, but I wasn't convinced. I looked at a few others, but nothing caught my eye. Then I discovered Code Igniter.

Code Igniter comes from the people who make Expression Engine. I had already heard great things about that, and I had even considered purchasing a license. Code Igniter, however, is free and open source. It's quite new (first beta was released in February) but it is incredibly professional and already very stable.

Code Igniter does absolutely everything I want it to, and nothing I don't want it to. It's incredibly simple and clean, so there are no surprises or weird tricks. It forces you to organize your code using an MVC structure (actually, a VC structure — using a model is optional). This keeps your code cleaner and easier to maintain. It also comes with a number of libraries that help with common web development things like email and uploaded files.

This weekend, I rewrote my whole custom-made blog code for this site. It only took about 4 or 5 hours, and it was actually fun to do. It also reduced the amount of code I had, and makes it much, much easier to maintain and change in the future. For example, until now I was too lazy to add contact pages properly, so I just added blog articles for Contact Me, etc. and pointed links at these. Now, I've changed the pages to use /contact/me and /contact/hire, and I could easily reuse my blog template. This change took about 10 minutes.

By default, URLs are of the form /class/function/parameters. But if you want to do something different (I use /blog/2006/5/article-name), you can set up routing rules for anything you want. Actually, Code Igniter is totally flexible to let you do whatever you want. Anytime I got stuck, I poked around in the documentation and found that there was something in place specifically for my problem.

Also wonderful: only the minimal amount of PHP is loaded to create each page. You can load classes globally, if you need them, but by default, you only load what you need when you need it. This keeps every page as fast as possible, something I was worried about with other frameworks like CakePHP.

Okay, that's enough ranting. If you use PHP, check out Code Igniter. There are some videos you can watch to see just how easy Code Igniter really is. The user guide is also a pleasant read and explains everything really well.


Interested in web development? Subscribe to my newsletter!

Comments

1 . GeoffC at 2006-05-15T09:42:46.000Z

GeoffC

Nice work. I have been playing with CI for a few weeks, tis very nice to work with.

Oh.. and come join us on irc.freenode.net / #codeigniter

:)

2 . Roberto Bechtlufft at 2006-05-19T00:17:16.000Z

Roberto Bechtlufft

I've been trying to understand MVC for a few weeks, but I always found it too complicated - I'm no PHP pro, I'm just a guy who likes to code now and then. But then I watched the video tutorial in Code Igniters site and, wow, that was a pretty good explanation! I'm already working on my wife's website using Code Igniters. Thumbs up!

3 . Jesse Skinner at 2006-05-29T10:40:54.000Z

Jesse Skinner

I love ruby and rails. But I think php still has it's place. Also, my hosting provider doesn't support ruby. So until my hosting contract expires, I'm pretty much stuck.

Regardless, when using php, Code Igniter is where it's at.

4 . zidane at 2006-06-01T23:20:50.000Z

zidane

Is it possible to use it with smarty as a template engine ?

5 . Jesse Skinner at 2006-06-02T06:54:19.000Z

Jesse Skinner

@zidane - you know, I was just wondering about that yesterday. I've never used smarty, but from what I can tell, you should be able to load smarty, call smarty functions, assign values and call the display function all from within the controllers of Code Igniter. It seems like it would make a great combination.

You also might want to ask/discuss this at the Code Igniter forum:

http://www.codeigniter.com/forums/

6 . Fredrik Wärnsberg at 2006-06-02T09:48:08.000Z

Fredrik Wärnsberg

Why not learn rails? The reason he made rails for ruby and not php was because php wasn't enough for what he was trying to do in the first place.

7 . chris at 2006-06-15T16:03:15.000Z

chris

Just looking through the documentation for CI for an hour or so and it looks very much like what I've been looking for over the past few weeks. So this is just a quick note to thank you for the headsup!

8 . rabi at 2006-08-31T09:38:18.000Z

rabi

This is good stuff. Tried it, it was nice. Anything like this for python? Im not a pro just a designer.

9 . Jesse Skinner at 2006-08-31T09:42:01.000Z

Jesse Skinner

@rabi - I've heard only good things about Django (for Python), though I've never tried it out. I'd like to one day, once I get a web server that supports Python...

10 . Chris Lamb at 2006-10-26T20:37:24.000Z

Chris Lamb

Fredrik, I do know Ruby and have built a clients application on Rails.

The problem for me with RoR was getting a server I could rely upon. It really seemed a patchwork muddling with Apache and fastcgi or lighttpd ... and on....

Has the situation improved?

11 . Terry Apodaca at 2006-12-06T20:24:03.000Z

Terry Apodaca

I'm using CI for the first time...to build a website for my family. I'll keep you posted on my findings and experiences.

12 . Jesse Eickholt at 2007-01-02T23:34:10.000Z

Jesse Eickholt

Just wondering if you'd be willing to share your code for your this blog. I'm looking to play around with CI and revamp my blog. I'd love to see what you did. I nice work with this site. It's very catchy.

13 . Jesse Skinner at 2007-01-03T00:04:41.000Z

Jesse Skinner

@Jesse - I've thought about releasing my code one day, but I'd want to package it up and make it more reusable first. I'll keep it in mind, and if I ever do, I'll be sure to announce it on here.

14 . angel at 2007-01-31T13:47:44.000Z

angel

hi, could you pls tell me how to use css with codeigniter? this code does not seem to work->

<link href="styles.css" type="text/css" rel="stylesheet">

it's my first time to use a php framework. i'm having trouble installing cakephp and simfony(?) and somehow managed to make codeigniter work (thanks to the video tutorials).

15 . angel at 2007-01-31T13:49:47.000Z

angel

nevermind, i found it out myself. just put the css on the root folder, not on the applications folder/subfolders. =p

16 . jonie at 2007-03-08T01:29:59.000Z

jonie

i watched the CI video and i had an orgasm

17 . Rudy at 2007-04-03T07:27:03.000Z

Rudy

In Romania 8 March is Mother's Day, so I understood why jonie had an orgasm ... :p

18 . martin at 2007-05-08T06:09:47.000Z

martin

hi there jonie......

r u sure u had an orgasm??wow.......

well i had a fun time learning CI with the help of the tutorial vids..

^^ just had a hard time with the css problem..........

19 . pedro at 2007-05-29T07:01:25.000Z

pedro

wow..

you guys are talking about CI + orgasms..
It must be good.

20 . Richard at 2007-07-17T08:26:57.000Z

Richard

Hey, I have to agree. I just downloaded over the weekend. CI is allot more intuitive than cake, and as it claims - is fast!

21 . Jenny at 2007-08-01T17:27:40.000Z

Jenny

From what I read, Smarty and Igniter do not really go well together - too much complexity overhead.

I have seen sites that used CI - it is fairly intuitive, BUT the front end and back end are not separated, which is very hard to manage. I would stick with smarty and good software design.

22 . squirre at 2007-08-22T06:53:55.000Z

squirre

hello, i'm a newbie in codeigniter, found same problem with css
but i think i know how to do that now...

i made a newbie tutorial in my blog
http://codeignitercamp.blogspot.com

23 . kik at 2007-11-24T01:08:42.000Z

kik

just to mention that CI work pretty well with projax.

24 . Brian at 2008-01-09T00:00:04.000Z

Brian

How is the front end and back end not separated in CI? It seems that they are, with the back end submitting finished values to the front end view files when finished.

It looks like it's not as slick as Smarty (ie. <?=$title?> instead of {$title}) but still does the job of separation, or am I missing something?

25 . eenx at 2008-03-02T16:21:34.000Z

eenx

I'll try it, thanks for the review

26 . Mohfeza at 2008-03-13T15:15:52.000Z

Mohfeza

Could you please
let me know if I can get CodeIgnitor hosing?

27 . Jesse Skinner at 2008-03-13T16:38:20.000Z

Jesse Skinner

@Mohfeza - the great thing about Code Igniter is, all you need is regular PHP web hosting, and you should be able to find that anywhere!

28 . Dhila Pamungkas at 2008-05-05T12:00:14.000Z

Dhila Pamungkas

I'm a real newbie on web programming..
I've never used PHP before..

One of my lecturer hired me to do some portal-making, and urged me to finish it this month with the assistance of CI, which I never used before..

So.. what do you think I should start with?

29 . Jesse Skinner at 2008-05-05T12:03:53.000Z

Jesse Skinner

@Dhila - Start with the CodeIgniter user guide and maybe pick up a good PHP beginner book. A month sounds like a tight crunch for learning and using a new language. Good luck!

30 . JM at 2008-08-05T00:48:26.000Z

JM

Code Igniter is an excellent framework, I'm using it in my two actual projects.

31 . henrihnr at 2008-10-16T04:48:11.000Z

henrihnr

anyone ever tried using DojoToolkit with CodeIgniter?
what do you think bout dojoToolkit to work with CI?
is it a good option? or there's a better option? thx

32 . JM at 2008-10-16T12:52:27.000Z

JM

I didn't use DojoToolkit, but I used jQuery and it fits perfect for CI. I used that combination for all my projects.
Good luck.

33 . Neighbor Webmaster at 2009-10-09T18:05:39.000Z

Neighbor Webmaster

For those who are interested in using Smarty with CodeIgniter, I documented my implementation here http://www.coolphptools.com/codeigniter-smarty . I also include some smarty plugins that make accessing language file information and validation errors easy.