Today I received a comment on my Laravel Auto-Generating Named Routes post that I felt deserved its own post.
Matthew Schenker wrote I see you’ve worked with CakePHP and CodeIgniter, and now you’re mentioning Laravel. I’ve been happily using CodeIgniter for a while now, but lately I see a lot of people mentioning (and loving) Laravel. I’m not looking for one of those “which is best” answers. Long ago, I learned that this is not a good way to look at various frameworks. But I’m curious — what are your general impressions when comparing these three frameworks?
CakePHP, CodeIgniter, and Laravel are all great frameworks in their own rights. They each have their pros and cons which I will cover here. Bear in mind that these are my opinions and forming your own by messing a bit with them is always the best policy. And as mentioned in Matthew’s comment, this is not an “OMG FRAMEWORK X IS TEH BESTEST!!!1!” post.
CakePHP
Cake, if I recall correctly, was one of the first PHP frameworks around back when spaghetti code was standard. The idea behind Cake was to make developing applications fast (ie, “convention over configuration”) by cutting down on how much code the developer needed to write. Less time working means more time making money.
Pros
- Built-in ORM which I’ve always really enjoyed. I really like how the results are in $post['Post']['field'] format. Building queries is really simple and you can fetch (for example) a blog post and all of its comments in one or two lines of code.
- Reverse routing. This makes maintaining links in an application so much easier. This means if you change a controller’s name at some point, instead of search/replacing 200 instances of “admin/foo” with the new “admin/bar” (and hoping you didn’t miss one) you simply update the route in one place. Any links using the reverse route array will automatically point to the right spot at runtime.
- Big community. Because Cake had been around so long you can find the answer for pretty much any question you come up with. If you can’t? They have their own website where you can submit questions, as well as (I believe) a mailing list.
- Plugins. This makes re-using code super simple and help keep the app folder clean (if, for example, you are distributing an app that uses modules).
Cons
- Incredibly slow. Recent versions of Cake (2.2.x as of this post) are much faster and more efficient than previous versions, but it is still one of the slowest frameworks. I am personally not sure how well it holds up when an app of it gets slammed with tons of hits. I am aware that Mozilla’s plugin site runs on an (old) version of Cake, as does Cake’s own bakery and Q&A sites, which all seem to run fine. I suspect it’s a balance between caching and server fine-tuning.
- TONS of lines of code. Some developers don’t care what’s going on under the hood; I like to be able to quickly find out how/why something works the way it does. The code is well documented but there’s just so much of it it can be overwhelming.
- Occasionally, you need to use code to reign in just how much it does. For example, my first step is to open my AppModel and set $recursive = -1 and adding Containable to Behaviors to prevent it from auto-grabbing related models and letting me tell it what I need.
- Autoloading can be awkward. In recent versions of Cake they’ve introduced lazy loading in the form of App::uses. Then, if you need to have access to (for example) the Model class, you do something like App::users(‘Model’, ‘Data/Model’) at the top of the file. This is, IMO, clumsy and no better than doing a require CORE_PATH.’Data/Model/Model.php’;
Conclusion: Personally, I use Cake if I need to put together a dynamic site quickly that I don’t foresee getting a lot of hits (like for a local restaurant, for example).
CodeIgniter
I’ve mentioned on here before that CI was the first framework I ever used and helped me finally understand the concept of OO programming. It’s certainly popular, and has been around a similar amount of time as Cake.
Pros
- Super easy to set up and use. This makes the entry level for a newer PHP developer much lower.
- Extremely well-documented, with examples in a lot of places to illustrate usage.
- Extremely fast.
- Huge community. As with Cake, since CI has been around so long you can almost always find your answer via Google, CI forums, or their IRC channel. This also means there’s lots of code contribution to help get things done (like Paypal libraries, etc)
- Sparks, the “hub” where CI packages go to hang out and be used.
Cons
- No modular separation by default. This is a big deal for me as I prefer keeping my code as separated as possible. There is Modular Extensions, which does the job, but I’ve never been 100% satisfied with it.
- Since 2.x broke CI has been 5.1.6+ for its minimum PHP version, but the whole $this->library, procedural function helpers, and extending a class by prefixing MY_ in front of it way of doing things just doesn’t work well for me. Perhaps this will change in 3.0? *shrugs*
- I personally have to extend way too many core files to get CI working the way I like it. The more you modify the core, the more you have to maintain later. I’d rather be coding something productive.
Conclusion: CodeIgniter is a fantastic framework for getting the hang of PHP and OO coding and for knocking a small site together fairly quickly with low overhead.
Laravel
Laravel is still in its early days compared to the “grandpas” of the framework world (I believe it was first introduced in 2011), but it has already gathered quite a following.
Pros
- Modularity is built in via “bundles”, making it really easy to drop in/reuse code across application
- Eloquent ORM is a simple, super fast ORM that makes working with database relations easy
- Very configurable and extendable. I can set up apps with the folder structure the way I like it and how it works best for me.
- Blade template engine. Very fast (compiles to PHP then caches the results) and very extendable. So easy to add new features without hacking the core.
- Artisan (CLI). Before I started using Laravel I had zero use for CLI tools like migrations and tasks. It’s so easy to create both of those things with Artisan that I can’t believe I waited so long to try it out!
- Reverse routing!
- Excellent documentation.
Cons
- It’s still quite new which can mean some instability with the code. However, since 3.x’s release (and certainly since 3.2.x’s, the most current as of this post) this has slowed down quite a bit.
- Laravel’s core files are all within (at least) the Laravel namespace and not all of the files in core use a namespace slash ( a \ ) in front of a call to another core file, which makes extending some classes a bit trickier. This is not a huge issue and one not every developer will need to worry about.
- Routing can feel a little odd sometimes. In my dynamic controller routing post I showed the workaround I used to dynamically route to an add function in any controller. I have not dug deep enough into the semantics of Laravel’s routing methods to understand why such a workaround is necessary but it does add another layer of complexity, IMO.
- Because of its newness the options for finding answers are still limited in comparison to CakePHP and CodeIgniter. However, the forums and IRC seem to be quite active with helpful people, so usually the answer is findable.
Conclusion: Laravel is currently my framework of choice. Its coding style meshes the best with my own which makes developing much quicker for me.
So there you have it! A personal comparison of 3 big players in the PHP framework world. As always, the best framework for you is the one that you code best in. The “Cons” foreach
framework are my personal beefs with each of them and should be taken with a grain of salt. The best advice I can give is to try them each on for size and see which you like best.
Matthew Schenker
/ August 5, 2012Hey Nerdy Mom,
Thanks for your response. I’m honored.
With frameworks, the more you learn the harder it can sometimes get. A year ago, I was all set with CodeIgniter (before that, I was actually fairly well set with Joomla, but that’s another story). Then I started giving other frameworks a try, and then started reading about Laravel, and suddenly the basic question of which framework to go with is not so basic any more!
Of course, this can be a bit stressful when you have various projects completed in different systems. But it can be good stress. Going through this process is necessary, since we cannot just close our eyes to what’s new and different.
I’m glad I discovered your blog.
Keep posting!
nerdmom
/ August 7, 2012Believe me, I know that feeling! Once or twice a year I’ll get gripped by the “Is this the best solution for this application?” question. It can paralyze you, but I’ve found that listing what I need the app to do and comparing the various frameworks’ pros/cons in relation to that helps a lot.
Thank you for your kind words!
Nacho
/ August 8, 2012Don’t forget shimpony?
nerdmom
/ August 8, 2012Well, Symfony was not one of the frameworks mentioned in the comment Matthew left.
More importantly, I do not have any experience using it which would make weighing in on it rather lopsided
Humberto Moreira
/ August 28, 2012How about speed with LARAVEL? You mentioned about cake being too slow, CI fast… where would laravel fit, in your opinion?
nerdmom
/ October 27, 2012Laravel (current stable version 3.2.x) is quite fast, on par with CI. Can’t speak for L4 as I’ve not tried it out yet, but I imagine it will be quite fast as well.
Clent Crumley (@clentdc)
/ September 8, 2012Great post. Im bouncing back and forth planning my next projects and am torn between Smarty and Laravel personally.
Look forward to reading the rest of your posts. Very ‘eloquent’.
(pun intended…)
nerdmom
/ October 27, 2012Haha…I see what you did there.
Tina
/ September 21, 2012A very helpful post in trying to decide which framework. Thanks for the detailed write-up.
Peter Drinnan
/ September 30, 2012I’ve worked CakePHP for a year then moved to CodeIgniter. Laravel looks interesting so I’ll be taking a look at that too.
Just a couple of notes on CodeIgniter 2+. There is a HMVC extension that is used by many of the newer CMS such as PyroCMS and Bonfire. It allows you to easily separate your modules.
For prefixing classes, you can define that in your config file so you don’t have to use “MY”.
In regards to extending core functionality, I have not yet had any major issues with updates. I have doie 8 core updates since CI version 2.0 and have yet so see any of my extensions break. If there are issues you can always use the migrations class to auto correct them.
Hope that helps someone.
nerdmom
/ October 27, 2012Codeigniter is very good for long-term stability of your code base, no doubt about that!
Watts
/ September 30, 2012Interesting comparison. I’m poking again at PHP frameworks after spending some time with frameworks in other languages, debating whether to go with Laravel or the Python-based Flask for a new project. (Still no idea, and I’m feeling like I’d rather go with Laravel 4 to see what “state of the art” PHP development is like — and L4 isn’t really out yet.)
One minor note, by the way: while the Mozilla plug-in site used to be based on CakePHP 1.1, they switched several years ago over to Django.
Anderson M Obah
/ October 26, 2012Thanks for this article is really.
Mubasshir Pawle
/ November 5, 2012great post… I still use cake and its being a year now,happy about it but looking forward for L4. does laravel have baking like Cake?
nerdmom
/ November 5, 2012Laravel has Artisan for managing command line stuff, though I don’t know that (out of the box) it will generate a plugin for you like Cake does. I do believe there’s a bundle that does that, though.
jeorgeban
/ November 23, 2012Laravel is a new framework which is best but still CakePHP is something of my choice as I think it to be easier to deal with giving me a desired result to what I am looking for. Laravel for me is on second position than comes CodeIgniter.
nerdmom
/ November 23, 2012CakePHP is certainly the one of the fastest to develop with, that’s for sure!
Vinay
/ December 15, 2012Well, Codeigniter is what fits to my needs very nicely. I can easily customize it’s core the way i want. Although i have to do a lots of work to make it happen. But how about creating a base app of your style like https://github.com/mikedfunk/Base-CodeIgniter-App
Lever
/ January 20, 2013Nice article. I’ve used Rails quite a bit, and PHP on it’s own, but never a PHP framework. I just stumbled on Laravel last week, but I think I’m gonna use it the first chance I get after reading your review. Thanks!
alan blount (@zeroasterisk)
/ January 31, 2013Thanks for the article, a good review and overview.
I’m a CakePHP user for many years, and am really happy with the 2x versions and am interested in the 3x alpha (object model returns, more like RoR)…
But I’ve heard good things about Larvel, i’ll check it out for something small sometime.
JunKiet
/ March 14, 2013Every moment always got new framework come out, we cannot 100% to follow up and to gain every single case, by the way, I prefer to build own framework.
- I just mentioned that, try to be ‘Easy’ way so that try to get less documentation, the more you defined, the more you problem may come out, the more people have to learn, and more documentation will do then.
Tony
/ April 5, 2013Great article! I really liked the way you compare without judging which one is the best/worst…
Good job!
Boris
/ April 11, 2013I senior year bachelor and I`m going to be speaking about frameworks,mvc and laravel in our of our beginner php lectures. I was looking for something like this because other than Laravel , I had worked only with 1 custom made framework that was based on rails and I had no experience with CI or Cake. Thanks
Jason F
/ May 3, 2013First, I’m impressed that a Nerd mom is coding. Awesome. We need more female developers like you… Now, about Laravel: If you dig through the Laravel 4 core, you’ll quickly figure out that the framework couldn’t exist without FIG, the framework interoperability group. What I mean is, the framework doesn’t appear to have it’s own core. Laravel 4 appears to just be a amalgum of various packages weaved together, to create a framework. I love the Laravel docs, and I like the code conventions. I also like Laravel’s restful routing (you can set something up quite similar to NodeJS on express with Laravel, that is, just pure routes & models / views – this works great with backboneJS / angularJS on the front-end). What I don’t like (about Laravel 4) is that nearly the entire core is just a set of adapters that import methods and classes from Symfony. In my opinion, Laravel should have written their own core and used Symfony’s core (seriously, when I dig through the source, I feel like I’m looking at a house of cards– and you know what happens to a house of cards). If you don’t believe me, install Laravel 4, run your composer.phar and dive into the generated composer/laravel folder. Based on my observations, 80% of the Laravel 4 core is coming from Symfony classes (if you dug through the layers of abstraction — that’s the ugly truth that gets revealed). Oh, and that’s another problem; if you’re going to develop a package for Laravel, good luck — you’re going to waste a lot of time with the crazy fascade pattern & ridiculous amount of abstraction they used. Now, Laravel explains that this abstraction is supposed to be for the sake of FIG so Laravel can borrow packages from many other frameworks (like Zend & Symfony). My company has been looking at Laravel to replace Kohana. So far we remain a bit wary of Laravel, mostly because it doesn’t really have it’s own core. Package development is a problem too. If you’re just a framework user, and you’re not going to create packages, then it might not matter. I do see Laravel as being much like CakePHP in the sense that it helps increase your productivity. You can get coding done fast (at least based on what I have observed so far). The question is whether you’re willing to adopt the underlying bloat of doctrine & symfony — powerful, but fat packages.
nerdmom
/ May 4, 2013Jason, I agree with a lot of your sentiments regarding L4. It seems that overall it’s trying to help you do everything and with that a certain amount of bloat becomes inevitible. I actually just wrote a post that addresses some of my own thoughts/reservations about it: http://nerdmom.wordpress.com/2013/05/04/composer-laravel-php-fig-oh-my/
Herdian Sc
/ May 6, 2013I like CakePHP. It makes us easy to maintain a code. Well we can implement caching to make this framework super fast.