Wednesday, June 1, 2011

Codeigniter Versus Yii - my thoughts

Codeigniter versus Yii, now this may open a real can of worms, as most comparisons do, but I have used both and have to come to the conclusion that whilst Yii is probably that slightly more polished, Codeigniter is going to be my framework of choice for next few years to come when developing websites in PHP.

Let's take a look at Codeigniter, it's easy to learn, easy to grasp and now that it has been upgraded to version PHP5 only from version 2 onwards, much more future proof. I also really like the way that you can really, really customise it to do your bidding. No need to use the command line to get it up and running and it will run with a very small footprint. You can also cache the hell the out of it at multiple levels to squeeze every little bit of performance out of it, take a look here for a detailed look at this.

Now let's look at Yii, completely object oriented and its major, major advantage - The CRUD generator. My goodness, this saves you time, lots of time. You create your database, design your schema and bang the Gii tool produces (as if by magic :)) your create, read, update and delete pages. No mucking around no writing SQL, it's all done through the (Rails inspired) Active Record Pattern - it's fair to say I fell in love with this almost straight away, I couldn't believe how easy it was to create this code. And this is what got me thinking...

I like Codeigniter for its flexibility, the way you could use both an active record pattern or traditional SQL, You could keep your database results in arrays or as standards objects, they leave it up to you. But I wanted, no, no... I needed a CRUD generator after experiencing the wonders of the Gii tool. As a freelance web developer in Lancashire (I know this sounds cheesy) time is money, so I scoured the web for one and I found a couple out there and none really lived up to my expectations, one was particularly good, but didn't really suit my needs. Like I said, I liked Codeigniter because of its flexibility, so I decided to bite the built and create my own CRUD generator for Codeigniter. Yeah, sure it was going to take a little bit of development time, but the time saved will definitely outweigh the initial outlay and it does, plus as my CRUD tool was my own, I could tweak and make changes very easily. Now, when creating large projects, creating new sections is not the chore it once was and now leaves me more time to make the other, more unique features, just right.

The main point that many people raise when they compare the two frameworks is the way that Codeigniter is not truly object oriented, whilst Yii is much more pure in its implementation. I suppose this is true, but when I create applications that are large, I need to know that I can hack away at them very easily and tune them to my specific needs and it is for this reason above all else that Codeigniter remains my PHP framework of choice.

When I first set out developing websites using PHP, I though this was the language I would use forever when it came developing websites. I als felt like I would never, ever use a framework as how could using some else's ideas and code be of any benefit to me, when I have wrote my own application. Not only is the code battle ready as it has been through countless improvements through being used in the community, it also oipens up your mind to new ways of thinking. I learnt to use Codeigniter first and Yii second, but there are things used in Yii, that I will and have ported over in to Codeigniter, the way Yii authenticates users for example, is a great way of accomplishing this task.

It's like I have mentioned before in other posts, do not do what other people tell you should do. Sure take on board what other people have, but stick to what you are comfortable with using as it is you that is creating the application and not them.

Labels: , , , ,

6 Comments:

Blogger Ryan said...

Any chance you've published your CRUD generator?

January 8, 2012 at 10:25 PM  
Blogger firmy007 said...

Hi Ryan,

I started off the CRUD generator as a bit of a pet project and has a become a great tool. Unfortunately I have modified it to a degree that suits and the systems I build. So my plan is to make a more public version of it and release it. If you email me (james@thefirmy.co.uk) I will send you the public version in a couple of weeks if you are interested?

James

January 11, 2012 at 8:29 AM  
Blogger Ed said...

Hi Ryan,

Just starting in with CI. Went along trying to write my own then decided it was not worth it just to avoid a learning curve.

I have integrated xajax and Smarty into CI as of day one.Now I can write a CRUD code generator that that generates a single controler, model and view per db table.

I'll follow up as things progress.

Ed

January 25, 2012 at 11:57 PM  
Blogger firmy007 said...

Hi Ed,

Sounds good. I like the sound of the 'xajax', however I have made it so my CRUD generator to be non-AJAX based, but may look at adding ajax submissions in a further update. It does however, use client side (as well as server side) validation using jQuery.

Here are the things I have built in my version.

Model Creation (using Active Record Pattern),
Admin Controller with server side and client side validation,
Public Controller,
Admin Edit (View) Page,
Public listing page with Pagination
Admin listing page with Pagination

The things I have to remove to make it open source are the features I
have built in for my own projects I work on; namely graphics and such. Just very, very busy with paid projects at the moment, so the hobbyist stuff has to go on the back burner.

James

January 26, 2012 at 1:03 PM  
Blogger Kong Jin Jie said...

I have many years of PHP development and have only started using frameworks few months back. I find CI very easy to use and easy to learn. Having read many blogs and forums, many mentioned Yii as framework with great potential. I tried it out and loved the way it put things together. It's like the developers of Yii knows what every developer is having a hard time at and solved it with their framework. I like the way Yii's ActiveRecord. Compared to CI, I still need to type lines of codes that does update(), insert() and delete() where Yii it's just save(). I hope to develop a module that brings the wonder of Yii into CodeIgniter such as ActiveRecord and widgets.

March 17, 2012 at 3:36 PM  
Blogger Unknown said...

Yii is actually quite badly structured and not really good OOP at all. A quick look at its core code can make your eyes bleed sometimes. Kohana is a nice framework similar to codeigniter too. Or you can try this new framework http://phpixie.com that's also very CI similar. Actually I think CI did a very good job as a framework if it has been forked that much =)

January 11, 2013 at 2:29 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home