Home » PHP » PHP MVC Frameworks » Choosing the best PHP MVC Framework – Part 1

Choosing the best PHP MVC Framework – Part 1

So, perhaps like me you are writing a fair bit of PHP and building some serious PHP apps.  Perhaps like me you have also decided that re-inventing the wheel for every app you write doesn’t make much sense and PHP by itself isn’t quite at a high enough level to be considered a framework.  I mean PHP is nice and all and there are fast ways to do many things in PHP, but there are far too many ways to do things in PHP and all you need is just one that works.  So having come to this realisation you decide that what you need is a PHP MVC Framework.  

Why a PHP MVC Framework?  Well to be honest the PHP Framework doesn’t need to use MVC as such, and you probably don’t even need a PHP Framework, just good PHP programming practices where you are separating the presentation (i.e. the View) from the business logic (Model and Controller).  You also want a standard way to do things like output common presentation elements (like forms) and do things like perform form validation, access the database and so on (I’ll cover this separately).  Whether you decide to roll your own (something I’m considering for reasons I will discuss later) or use an existing PHP MVC Framework, you still need some sort of a framework, as otherwise you’ll be writing the database access code for every app and that just doesn’t make much sense.

So, you realise that you indeed need some sort of a framework.  The next question is what framework.  For now I’ll concentrate only on PHP Frameworks but will at some stage discuss other technologies such as ASP.NET Forms and ASP.NET MVC as that’s a topic of it’s own (i.e. PHP MVC Frameworks vs ASP.NET MVC).

Through your research you’ll find that there are MANY PHP Frameworks available, and indeed I dare say a few TOO MANY.  Most of these frameworks are MVC Frameworks.  The reason for this is that MVC is a well understood and accepted software design pattern that aims to separate the presentation from the business logic (and presentation specific business logic (i.e. Controllers).  To be honest in PHP, although some may argue otherwise separation of the Model and Controller probably isn’t all that important for a simple app where you don’t use the same model in multiple conrollers, but it does become important if you’re looking to re-use the model in multiple controllers.

It’s also worth quickly covering off what the Model actually is, although that probably deserves a post of it’s own as it’s so mistunderstdood.  In broad terms the Model is really just Domain Logic, or code that isn’t (or shouldn’t be) tied to a particular user interface.  In case of PHP the different front ends may be your HTML based UI and XML/SOAP based Web Services, both of which should use the same model, and hence the model shouldn’t really have any UI specific logic.  For example if validation is done in the Model (which is where it belongs) then the model shouldn’t just output HTML when an error is encountered as that’s specific only to HTML.  This concept is much more evident in .NET Applications that have both an ASP.NET front-end and an Windows Forms front-end and often a Web Services interface.

Anways, you’ll probably find, there’s quite a long list of MVC Frameworks (see PHP Frameworks and Wikipedia although PHP Frameworks is the better source)… Here are some of the best known ones and my brief thoughts on them… I’ll cover each in a separate post.

  • Zend Framework – A well known enterprise level php framework, with a an MVC component, very complete and cohesive, but also very performance heavy.  Unless you have a Dedicated Server, a VPS or at least opcode caching on your shared hosting it’s probably not a good idea.  Also it’s a glue framework, so it won’t force you to do things in a particular way, which can be both good and bad.
  • Yii Framework – A relatively new PHP framework, but well architected and feels very similar to ASP.NET in some ways.  This is one I felt most comfortable with.  It is strictly PHP 5 and Object Oriented.  It uses a class loader to be as efficient as possible, but isn’t superfast.  Fast growing community.
  • Kohana PHP Framework – An offshoot of Code Igniter that is strictly PHP5 and Object Oriented.  Quite a nice framework, but doesn’t feel quite as nice as Yii… Performance is similar to Yii.  Pretty big elite community.
  • Code Igniter – Very popular PHP MVC Framework, with a massive community, but still supports PHP 4 and as a result has code for interoperability, thus slowing things down a little for no good reason if you’re not using PHP4.  Doesn’t feel quite as nice as Yii or Kohana.
  • Solar PHP – A relatively new recently released PHP Framework.  Doesn’t have much of a community behind it and is pretty much a lighter version of Zend Framework.  It’s only at version 1, so not sure you want to take the risk.
  • Doo PHP – A fairly lightweight PHP MVC Framework, that claims to have the best performance of all PHP frameworks.  Although that may be the case it forces you into using ORM and just doesn’t feel all that natural.  Even class names are weird… Seriously, what does SqlMagic actually mean?
  • Symfony – Quite a cohesive framework, but slow so best only left to enterprise development, in which case Zend is probably a better choice.
  • CakePHP – Quite a popular MVC Framework but slow and also forces you to do things its way.
  • ezComponents – An older framework, somewhat similar to Zend in terms of being a component framework, also relatively code heavy.
  • Seagull – Build on PEAR, which is more a component library than a framework, havn’t really looked into it much, so can’t really comment.
  • Ash.MVC – A very basic PHP MVC Framework that does nothing but MVC itself and DB access.  Not something you’d consider writing your serious apps with.
  • Qee PHP - A chinese PHP MVC Framework, unless you speak chinese it’s probably best to steer clear.
  • Think PHP – Another chinese PHP MVC Framwork, so unless you speak chinese, probably best to steer clear

With so many frameworks available you really need to work out how you’re going to work out which is the right framework for you… I will exlore this in more detail in the following parts of this post, but briefly, the things you need to think about are:

  • Performance – This depends what you’re developing, but you really don’t want a framework to make your website slow if starts getting some serious hits.  Although this needs to be balance off against other factors.
  • Cohesiveness – Its best for a framework to be cohensive rather than just a few different components thrown together out of different places (e.g. PHP Classes).  This will make it easier to develop with.
  • Comprehensiveness – You don’t want to end up with a framework that can’t do many of the things you need to do in day-to-day development or you’ll have to go looking for solutions.  For example, very few frameworks atm have a HTTP Client class!!!
  • Feel – It’s important that a framework feels natural and that class names make sense and so on as it will make your development faster.  Also you don’t an MVC Framework that forces you to use ORM or Active Record, as that’s not something you absolutely must or even should use.
  • Documentation – You don’t want a framework that’s undocumented so you’re forced to go wondering through code to work out how things work.  Its good to have lots of examples.
  • Community – It’s pretty important for a framework to have a large community as that means that someone will most likely have come across and solved the problem you’ve come across.
  • IDE Support – You want to make sure that the frameworks works in a proper PHP IDE like Eclipse PDT and NetBeans (I’ll post on this separately).  Having the framework with proper comments on classes and functions makes development in an IDE much easier.  Also it’s best to use a framework that doesn’t use the Registry for absolutely everything or in such a way that type inferencing and code completion doesn’t work.
  • Time Around – An older framework will tend to have a larger community, fewer bugs, solve more of the common problems and so on.
  • Interoperability – How easily can the framework work with other frameworks, classes and so on, in case it doesn’t do what you need it to already. Is there an easy way to extend it?

So when comparing frameworks you need to take all these aspects into consideration.

Personally after spending a fair bit of time on the frameworks I narrowed my choice down to:

  • Yii Framework – Because it feels most natural and is quite comprehensive, although I don’t like that it pretty much forces you into Active Record and ORM and isn’t very performant.
  • Kohana PHP – Because it’s still strictly PHP5 and OO and hence doesn’t need interoperability code like Code Igniter.  However, some things are a little overdone, which impact perfomance. and some bits don’t feel natural. e.g. class naming for static classes (e.g. date_Core).
  • Zend Framework – Although it’s a bigger beast it is the most comprehensive and with the biggest community.  I won’t dare using for an app to be hosted on shared hosting though as it’s too low and heavy for that.
  • Code Igniter – It’s lightweight and all, but I don’t like the PHP4 interoperability and not being OO, althought that doesn’t really matter so much as a static class and just functions is much the same thing.

There’s actually a great post on Beyond Coding that comparing Yii vs Kohana vs CodeIgniter.  It considers most of the aspects I’ve gone over but doesn’t really look into performance (as all those frameworks perform in the same ballpark).

There is also this other pretty good post comparing CodeIgniter vs CakePHP vs Yii

In the future posts in this series I’ll expand on the criteria I used to evaluate the PHP MVC Frameworks and then also compare specific frameworks.  I’m also going to look specifically at framework performance as that’s absolutely paramount.

  • Share/Bookmark
Categories: PHP MVC Frameworks Tags:
  1. Alex
    April 6th, 2010 at 23:44 | #1

    Great article and really actual for me! Looking forward for new ones!

  2. Dominic Xavio
    April 8th, 2010 at 17:53 | #2

    Do consider Fat-Free in your review. It’s the newest kid on the block, with some tricks of its own not found in others. http://fatfree.sf.net

  3. April 8th, 2010 at 21:26 | #3

    Well I’ve had a look at FatFree and I can’t say that I’m a fan at all. Creating one big class (sorry 3 big classes) and calling it a serious frameworks is hardly something people should put a lot of trust into. On top of it FatFree manages to sneak in ORM and a templating language (i.e. both things that are bad for performance). I’ll stick to a real framework like Yii or Zend for enterprise projects and would encourage others to do the same if they expect their projects to actually evolve into something bigger than a small personal website.

  4. Dominic Xavio
    April 17th, 2010 at 04:41 | #4

    You don’t have to be a fan, just a responsible editor. The PHP 5.3 version of the frameworks in your list are still vaporware. FatFree delivers.

  5. Hudson
    June 10th, 2010 at 02:48 | #5

    In the cut down list of choices I almost agree with you but would replace CodeIgniter by Symfony for reason of non OOP and mixed PHP4 and PHP5 support which doesn’t make any sense in new projects today.

    Though, I am a big fan of Yii and chose it as our primary framework in our company. Yii is not ASP.NET liked but its brother, Prado. I recommended it for personal as well as team/company for these reasons:

    - New emerging framework, the authors keep adding cutting-edge libraries and components into it, for example, new code generator tool Gii.
    - Well documented, well structure and OOP strict make learning Yiii is pretty fast
    - Very lightweight and easy to install compare to Zend or Symfony. Also extremely high performance compare to these 2 big names.

    FlexicaCMS, a new rising CMS based on Yii is a great CMS/sandbox that worth to check out. http://www.flexicacms.com

  6. August 31st, 2010 at 10:17 | #6

    For anyone interested in a better platform have a look at: http://www.xtend-it.com
    Offers the best approach on what a framework should be and has a lot of unique features. It will soon be released I just want to finish some new features

  7. August 31st, 2010 at 10:58 | #7

    Seems like it could worth a look from a feature and design perspective, but the big thing will be getting a community around it. My opinion is that it’s important to get a framework that’s easy to use and learn too. Kohana is an example of a framework that’s quite good, but lacks the community and hence doesn’t get the recognition it probably should.

  8. Andras Szepeshazi
    November 8th, 2010 at 03:53 | #8

    Although raised a couple of very solid points, I think the approach of choosing a PHP (MVC) framework for just anything is not valid anymore. Based on your needs, you’d rather choose from a subset of frameworks. You need a blog site, you go to Wordpress or any of it’s competitors. You need social networking, you turn to Elgg or Dolphin or whatever is on your shortlist. Just choosing a framework because it has a nice MVC approach is kind of choosing a car based solely on color. It is nice to have it in navy blue, but that won’t help me on acceleration or trunk space or mileage – whatever my current priorities might be.

  9. November 8th, 2010 at 04:02 | #9

    I was looking specifically at building a custom application, not blogging or social networking.

  10. Joe
    November 22nd, 2010 at 03:11 | #10

    It’s probably worth mentioning lamplighter as well: http://lamplighterphp.org . The structure is easy for most PHP developers to get comfortable with right away, and the helper scripts make it pretty easy to set up (at least I found)

  11. November 22nd, 2010 at 07:27 | #11

    Yeah, I’m not a big fan of the smaller less known frameworks as they just don’t have the same big userbase and hence the number of widgets and support is not as good. The other thing that I hate is when instead of using PHP for templating you have to learn some sort of a new templating language like smarty… Just stick with PHP!

  12. John Fro
    June 28th, 2011 at 04:19 | #12

    Anyone familiar with Dolphin?

  13. June 28th, 2011 at 05:14 | #13

    I wouldn’t go with it as you’re better off with a framework which has a very large user base.

  14. January 20th, 2012 at 15:20 | #14

    “But Yii isn’t superfast.”
    It’s actually the fastest one…
    http://www.yiiframework.com/performance/

  15. January 29th, 2012 at 23:13 | #15

    All that performance is a relative measurement… With opcode caching they’re all much of a muchness

  16. July 19th, 2012 at 23:12 | #16

    @John Fro
    It is soooooooooooo messy and complicated code.

  17. November 3rd, 2012 at 05:01 | #17

    I have worked on zend, cake and CI… my rating is 1. CI 2. Zend and 3. CakePHP

  18. Alex Dev
    November 9th, 2012 at 03:57 | #18

    I`d recommend you to have a look at Yii. To my mind it`s the most efficient one. It`s easy and clear and thanks to several good extensions like bootstrap http://www.yiiframework.com/extension/bootstrap/, backvendor http://www.yiiframework.com/extension/backvendor/ or coco http://www.yiiframework.com/extension/coco/

    It really helps to save lots of time in the early stages of development.

  1. April 7th, 2010 at 18:33 | #1
  2. April 8th, 2010 at 04:05 | #2
  3. April 25th, 2010 at 09:22 | #3
  4. April 25th, 2010 at 14:06 | #4
  5. August 25th, 2011 at 22:47 | #5
You must be logged in to post a comment.