Comparing Laravel, CodeIgniter, & CakePHP

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.

About these ads
Leave a comment

41 Comments

  1. Matthew Schenker

     /  August 5, 2012

    Hey 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!

    Reply
  2. nerdmom

     /  August 7, 2012

    Believe 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! :)

    Reply
  3. Nacho

     /  August 8, 2012

    Don’t forget shimpony?

    Reply
    • nerdmom

       /  August 8, 2012

      Well, 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 :)

      Reply
  4. How about speed with LARAVEL? You mentioned about cake being too slow, CI fast… where would laravel fit, in your opinion?

    Reply
    • nerdmom

       /  October 27, 2012

      Laravel (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.

      Reply
  5. Great 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…)

    Reply
  6. Tina

     /  September 21, 2012

    A very helpful post in trying to decide which framework. Thanks for the detailed write-up.

    Reply
  7. I’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.

    Reply
    • nerdmom

       /  October 27, 2012

      Codeigniter is very good for long-term stability of your code base, no doubt about that! :)

      Reply
  8. Interesting 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.

    Reply
  9. great 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?

    Reply
    • nerdmom

       /  November 5, 2012

      Laravel 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. :)

      Reply
  10. Laravel 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.

    Reply
    • nerdmom

       /  November 23, 2012

      CakePHP is certainly the one of the fastest to develop with, that’s for sure!

      Reply
  11. Well, 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

    Reply
  12. Nice 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!

    Reply
  13. Thanks 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.

    Reply
  14. Every 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.

    Reply
  15. Tony

     /  April 5, 2013

    Great article! I really liked the way you compare without judging which one is the best/worst…

    Good job!

    Reply
  16. I 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

    Reply
  17. Jason F

     /  May 3, 2013

    First, 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.

    Reply
  18. nerdmom

     /  May 4, 2013

    Jason, 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/

    Reply
  19. I like CakePHP. It makes us easy to maintain a code. Well we can implement caching to make this framework super fast.

    Reply
  20. Aaron

     /  June 7, 2013

    CakePHP has since been proven faster than Codeigniter: https://github.com/confact/Thesis-PHP-Framework-Performance

    Reply
  21. When we say ‘CakePHP is slow’ it does really warrant our late night researches. However, I compared the 2 frameworks Laravel and CakePHP. No doubt Laravel is .. light-years advanced in architecture but with steep learning curve and rapid releases, 2 years 4 versions, with no backward compatibility (not in the abstract though), it is slow in development. Cake does not need several line of codes if you follow their semantics, which does ask for more practice on it.
    Just wanted to know if your blog judgement is based on ‘actual’ web app development or just install-create-a-blog and blog about it?
    Not sparking a debate (because we can play marry-go-round forever on this) but just want to know the insights.

    regards,
    K

    Reply
    • nerdmom

       /  July 25, 2013

      K, I have developed a handful of small applications in both Cake and Laravel (version 3). Compared to Laravel 3, Cake *is* quite a bit slower and requires a lot more optimization to get it chugging along as quickly as Laravel.

      That being said, I’ve noticed recently while working with Cake 2.3 and later “L4″ that L4 isn’t much faster than Cake (this is going on straight up memory usage and execution time, no fancy tests). Laravel seems to have gone from a sleek, modern, CodeIgniter alternative, to a workhorse that can do a LOT of stuff.

      Also, it does seem that Cake gets a bit faster with each release they’re putting out, so that’s good :)

      I agree with your assessment of Laravel’s releases; they certainly have trail blazed over the past couple of years. The talk is that these kind of rapid-fire releases and such will slow down now, but that remains to be seen.

      Personally, if I were just getting into frameworks, I would be very intimidated by Laravel’s current version. There is a *lot* to wrap your head around, especially if you’ve never worked with OOP much.

      But, at the end of the day we should all use what helps us code the fastest, whether it’s procedural PHP or something like Symfony2 :)

      Reply
      • Thank you for your reply. I guess, I will be sneaking bit more into L4(latest build) or perhaps make an app for one of my client, though that would be a risk… but, worth taking! Glad I have found your blog.
        Keep up!
        Cheers!

  22. I’m taking your advice and siding with Laravel for my project. It was a hardsell but your conclusion did it. Thanks.

    Reply
  23. Greetings,
    I am returning to this discussion! Thanks for quoting me in the article.

    I’ve spent the past year working with many frameworks: Laravel, CodeIgniter, Symfony, Yii, CakePHP, and even one called PHPixie.

    My lightning-fast assessment: Laravel (in my opinion) seemed at first to be the answer to all our framework needs, but somehow it seems to have become a convoluted mess. CodeIgniter, strictly speaking, is great, but I worry that it has no future. Symfony seems amazing, but I feel like I can’t get my mind to embrace the whole thing.

    PHPixie is really nice, but it has mysterious origins and support — which makes sense given its name! I’d actually rank this one higher if I knew where it was heading. Need a PHPCrystalBall framework for that!

    I’m down to Yii and Cake — very impressed with both of these frameworks for various reasons, and they both feel intuitive and stable to me.

    The one area I am wondering about now is security. How many steps does it take to validate forms, and also protect against XSS and injection attacks? It is likely to be the tie-breaker between Yii and Cake.

    I’d be very curious to hear comments on how you think security measures up on each of these systems.

    Thanks,
    Matthew

    Reply
    • nerdmom

       /  October 9, 2013

      Well, I’ve never used Yii at all, so I can’t comment on that. Cake seems to be reasonably secure; I know they had a couple of security flaws found over the summer that were patched very quickly. Each version seems to get a bit faster, and since version 3 will be PHP 5.4+ only, I am quite eager to see how it measures up. :)

      I’ve been happy with Cake for the projects I’ve used it for; if you don’t need to go too far outside their box with your requirements, it’s great for rapid development.

      Also, I believe PHPixie started as a fork of Kohana 3.3 and has started to evolve from there (if you search Kohana’s forums you may find it).

      Reply
      • Thanks nerdmom! I’m testing testing testing Yii and Cake. I really like them both. Yii has some neat code-generation tools, which get you started faster than Cake. But once the app is set up, I find the syntax and logic of Cake to be clearer and faster to use than Yii.

        These two frameworks are REALLY close in my mind.

        One area I am thinking about is job opportuniuties. I’m doing all right as an independent, but if I ever wanted to join an agency I wonder whether Yii or Cake is better to know? Strictly going by the numbers, CodeIgniter is still the best in jobs, which throws a wrench into the whole “job opportunity” logic. Cake seems to be better than Yii for job opportunities.

        The other thing that worries me sometimes is that Yii is steadily rising in popularity (if you trust Google Trends data), while Cake has seen some drop-off in the past 1.5 years. Then again, Cake appears to be climbing slowly back up this year.

        Then there’re the very odd issue that Cake has no official user forum (as far as I can tell).

        Still, I’m tending towards Cake…

        Thanks for yhe great place to discuss these matter!

  24. Joe704la

     /  October 9, 2013

    nerdmom, you mentioned that CodeIgniter “helped you finally understand OO concepts. I am in the process of trying to fully understand OO concepts and I do to a certain degree but still get confused much of the time. I am not looking to move into using a MVC framework to force myself good programming conventions as well as developing in OOP and MVC. Would you recommend starting in CodeIgniter or Laravel?

    Reply
    • nerdmom

       /  October 9, 2013

      That’s a tough one. CodeIgniter is much simpler out of the box and, for me, was what finally made object orientation make sense. Laravel (v4) has a lot of concepts that CI doesn’t (facades, service locator pattern, etc).

      Laravel could conceivably grow with your abilities and project(s), whereas many CI developers reach a certain point where the framework’s limitations get in their way. On the other hand, Laravel has a higher learning curve than CI, and may end up overwhelming you.

      I would start with CI, at least until I had a firm grasp on OO concepts. Once you have that down, jumping to Laravel probably wouldn’t be such a shock. Hope that helps! :)

      Reply
  25. Thank you. Helped me choose a framework. My takeaway is laravel seems to be most in line to the way most minds think.

    Reply
  26. CI is dead and laravel is .. well see for yourself what some dude put together: https://gist.github.com/anonymous/8565929
    You might want to reconsider your choice of framework if its not a “hobby site” you are working on.

    Reply
    • nerdmom

       /  January 23, 2014

      Mark, that’s an interesting list. Thanks for sharing it.

      I did post a (sort-of) follow up to this particular post that expresses my own concerns/reservations about L4:
      http://nerdmom.wordpress.com/2013/05/04/composer-laravel-php-fig-oh-my/

      In a nutshell, L4 seems great for rapidly developing applications, but the underlying bloat makes it hard to dive into the code and figure out how things are wired together (IMO).

      Reply
      • I don’t quite see the reason behind the Laravel hipe.
        You can develop with Cake even faster – and page speed is no reason at all. Far more important is the development time you can safe in the short and long run. Also you can bring any application up to speed regarding page loads if you use the proper hardware and server setup :)

      • Greetings,
        to S Rahul Bose and mark: I strongly disagree that Laravel is so great. The syntax of Laravel is nice. But the direction of the underlying framework should be a warning sign.

        As nerdmom says, Laravel has a lot of code bloat/confusion. If you spend some time on the Laravel forums, you’ll see an increasing number of situations where someone reports a problem that is difficult to diagnose because there are so many disparate components stitched together under Laravels hood. Laravel has a squad of developers who post positive statements everywhere they can. That’s fine. But check the Laravel forums and you’ll notice a few trends: (1) A growing number of people raising alarm bells about the bulk and slowness of the framework; (2) A steep decline in activity over the past few months; (3) People who post issues with Laravel are often attacked as not being good enough developers (even told they should not use the framework) then the person who posted the problem just disappears.

        My prediction for 2014: Laravel will settle in as just another framework, and we will get past this period where we are made to think that Laravel is not only the savior for PHP but that we bettr not criticize it.

        I’ve spent countless hours testing several frameworks. I agree that CodeIgniter is dead. But when it comes to which framework is solid, logical, has a strong developer community, just works, and has a track record with major applications, I think you have to take a fresh look at CakePHP. With CakePHP 3.0 on the way, I definitely believe we are looking at a resurgence for this framework.

        There is this faulty idea circulating about that CakePHP is on a downward path, and that Laravel is on a forever rise. But I think the truth is more that CakePHP is so mature it has achieved a kind of calm, serene attitude. CakePHP is not so flashy and noisy. But don’t mistake calmness for a lack of quality!

  1. Composer, Laravel, PHP-FIG, oh my! | A Nerdy Mom!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 127 other followers

%d bloggers like this: