Bells ringtonesAl Green ringtonesLil Jon ringtonesOtis Redding ringtones

Notes on Choosing a PHP Framework: A Comparison of CakePHP and the Zend Framework

UPDATE:Parlez vous Français? Guillaume Rossolini has created a French translation of this article.

Are you considering using a PHP framework for your next project? If so, this article's for you. I've narrowed down my choices to CakePHP and the Zend Framework and have documented my findings here.

Four or five years ago I began researching PHP application frameworks. At the time, the pickings were very slim, especially when compared to those available to Java developers. On the advice of an ex-Coldfusion developer, I settled on the PHP port of Fusebox, the de facto Coldfusion framework. Fusebox 3 provided a convenient set of loose conventions for structuring applications, organizing code, naming files, and controlling flow. It served my development team well and applications we built with it are still up and running.

I took a two-year "break" from development and upon my return I found more PHP frameworks than you can shake a stick at. Now I need to find a solid MVC-based framework and after reading dozens of articles and completing a few tutorials, I've narrowed my focus to CakePHP and the Zend Framework.

Before going further, let it be known that my point of view is that of someone with plenty of application development experience but without a formal IT or CS degree. I can't go on about the merits of one design pattern vs. another. I do, however, understand the need for convention, the advantages of modularity, and the efficiency of easily repeatable processes.

Please note that symfony, Prado, Code Ignitor, and many of the other PHP frameworks all look quite capable of meeting most project needs. If you're a fanboy of another framework, please don't espouse it's merits here. I am, however, interested in hearing about your general experience in learning a framework, particularly in the context of your professional background.

Here's a comparison and a few conclusions after spending a bit of time with both CakePHP and the Zend Framework. Please note that my quality scale range is: poor, fair, good, excellent.

Feature Comparison of CakePHP and the Zend Framework
Feature
CakePHP Zend Framework Notes
License
MIT
BSD
Each of these licenses is fairly flexible. Carefully consider how your application will be used and distributed. It's also important to consider compatability with 3rd-party extensions included in your application.
Compatability
4 and 5
5.1.4 or later
I'm curious to know what CakePHP's PHP 4 support plans are. I would wager that Zend's focus on PHP 5 provides it with performance advantages.
Documentation
CakePHP's documentation is good but Zend's API documentation is more thorough.
Community
Both frameworks have active user communities. In addition to official channels, there are also several 3rd-party community sites easily found through Google. CakePHP has done an excellent job of marketing their framework considering that they don't have the corporate backing that ZF has.
Tutorial/Sample Availability
excellent
fair
CakePHP's Bakery provides an extensive collection of user-submitted applications and code samples. The IBM developerWorks CakePHP tutorials and aritcles are excellent. The Zend tutorials I've reviewed are good but require a siginifcant amount of MVC design experience. The ZF beginner's videos, however, are very helpful. CakePHP provides screencasts too.
MVC
strict
optional
These points are the biggest distinctions between these frameworks and probably the most important factors when choosing one over the other. CakePHP has very strict naming and code organization conventions while Zend only enforces conventions when employing its MVC capabilities.
Conventions
strict
flexible
Configuration
PHP file
PHP Array, XML, or
INI files
This difference doesn't seem like a sticking point to me. If you're a fan of build tools like ANT, you might prefer Zend's choice of XML.
Database Abstraction
PHP, PEAR, ADODB
I may be wrong, but I get the impression that PDO is gaining favor in the PHP community.
Security
Both frameworks take security very seriously and provide authentication and ACL-based authorization. Both approach ACLs in a similar fashion and both provide a high degree of flexibility in creating and applying ACLs.
Data
Handling
good
excellent
Out of the box, both frameworks provide data validation and sanitization mechanisms. Zend provides more validation options, but CakePHP's validation is easily extended via PCRE. CakePHP provides a single data sanitization mechanism where Zend provides various filters to run data through.
Caching
good
excellent
Both provide file-based caching of pages. Zend supports several cache backends, including APC, SqlLite, and of course, the Zend Platform.
Sessions
excellent
excellent
Both provide robust session handling.
Logging/
Debugging
good
excellent
Both provide application logging. IMHO, the Zend_Debug class gives ZF the edge in this category.
Templating
PHP-based
PHP-based
Coming from a UI design background, templating is of particular interest to me. If you've developed templates for WordPress or Drupal, you'll feel right at home with CakePHP. The Zend Framework requires a bit more work to get templating up and running (see Zend_View and Zend_Layout). It's possible to integrate 3rd party templating engines, like Smarty, with each framework.
Helpers
good
excellent

Both frameworks provide basic helpers to handle AJAX, forms, and time conversions. CakePHP provides a nice HTML helper which is absent in ZF but ZF provides a wider range of helper classes.

JavaScript/Ajax
good
fair
CakePHP comes with built-in support for Prototype and script.aculo.us while the current stable release of the ZF doesn't support any specific JavaScript framework. ZF does provide JSON support and the 1.5 release adds AJAX form featues. I'd like to see both provide a wider range of support for 3rd party JavaScript Frameworks, particularly Jquery and YUI.
Web Services
good
excellent

Both provide support for REST and XML-RPC as well as basic XML feed parsing. Zend Framework also provides support for several popular web services including OpenID, Reflection, Akismet, Amazon, Audioscrobbler, Delicious, Flickr, Simpy, StrikeIron, Technorati, and Yahoo.

Localization
good
excellent
Both support localization through stadard means (i18n, l10n). CakePHP is adding/improving support in their upcoming 1.2 release. Zend appears to have better support for localization and translation.
Unit Testing
yes
yes
Both frameworks provide support for this feature that far too many of us avoid ;) I have yet to evaluate unit testing support.

Conclusions and Recommendations

I hope to use both of these frameworks soon, but in the short term I'll most likely base an upcoming CMS project on CakePHP. I do plan on using the Zend Framework, if for nothing other than expanding my application design skills, PHP 5 OO knowledge, and understanding of MVC.

CakePHP: Hit the Ground Running Fast

If you are new to MVC, require PHP 4 support, want stricter conventions, or want powerful code generation tools, CakePHP is the choice for you. CakePHP's Scaffolding, Bake, and ACL scripts provide definite advantages when the need to quickly build an application arise.

The Zend Framework: A Model of Flexibility

If you know MVC, need more control over application design, or want built-in support for popular Web services, the Zend Framework is choice for you. The Zend Framework provides a greater degree of flexibility in designing applications that scale effectively in high-performance environments.

The bottom line is that both frameworks are rapidly evolving in response to user demands. Gaps in each are being filled and there seems to be no lack of demand for developers with skills in each framework.

Feel free to share your experience in learning any framework.

Comments

fabulous article, did you know?

Just wondering if you are aware that the Joomla 1.5 CMS has MVC include as part of the framework

Most suitable

I think the major doubt inside the decision of choosing frameworks is which one fits better on some specific project.

I have doubts on that, and no comparison I have found show me clues that would point the solution...

For example, which one would be more suitable for multiple projects with common data, sharing common database?

Is it possible to say what cases CakePHP will work better than Zend Framework? As well the opposite?

No comparison is going to answer this question

No comparison is going to answer this question for you completely. Hopefully these types of comparisons can shed light on a few points that pertain to your project.

There are too many variables, considerations, and preferences. I encourage you to download and try those frameworks your considering.

Cake has the edge on testing

One big selling point for CakePHP is that its test framework is Simpletest, while ZF uses PHPUnit. The difference between these two is that simpletest has better mock object support.
This is important if you test first, then write code--which you really should try! it's liberating--because your controller frequently interacts with model (database) and view, so it's nice to know, by using a mock database/view, that your controller is doing exactly what it should. In other words, you have to have the mocks in order to fully test (i.e., define by means of tests) the controller's API.

Basic search

tells eveything. Google results of cake are around 3.700.000 pages. Zend are around 637.000 :)

Also Cake is now version 1.2. Imagine the pain and suffer during all this version staging period.
I would like to go with mature framework.

Peace
Kunth

Volumes of searches really

Volumes of searches really tells you absolutely nothing. I found it best to try out the basic tutorials on the frameworks and see what you like the look of for your project.

Also - I can't say I have found Zend's documentation 'excellent' as it reports above - which is another reason I have chosen Cake to try for the next project.

Thanks a lot for this

Thanks a lot for this article. izle

Searches narrow down the list to test

I disagree. I think searches shorten the list of things to download and try.

Something to be said for quality

Quantity and age are certainly not representations of quality or appropriateness. I encourage all who are evaluating PHP frameworks to dig a bit deeper. I've been spending quite a bit of time with the Zend Framework since writing this comparison and have been please with the results achieved so far.

ZF has announced a partnership with the Dojo JavaScript Toolkit and the upcoming ZF command line tools. Each of these announcements demonstrate that the ZF is quickly bringing it's feature set up to that of other PHP frameworks.

Another point that I didn't include is training. The ZF is backed by training provided by Zend.

All I'm trying to say is that folks should dig a bit deeper when deciding what might work best for them.

Several things about Cake

Just my 2c:

Compatibility: Cake will switch to PHP5+ only in 2.0 (according to https://trac.cakephp.org/milestone/2.0.0.x)

Configuration: Cake has a default configuration in a PHP file, but there is nothing stopping you to override it and read the configuration from an XML file or database or whatever you want.

Caching: I believe Cake supports more than just "file cache": www.cakephp.org/files/OCPHP.pdf

Very nice comparison though!
Cheers!

Nice article!

A great comparison between the two frameworks Chad! :-)

Inspired by your comparison, I wrote a similar article/comparison on CodeIgniter and Kohana.

Link: http://thislab.com/2008/02/23/notes-on-choosing-a-php-framework-a-quick-...

Hopefully some people will find it useful.

Cheers,
Fred

Great comp!

Yeah i have to say it's a great comparison. I always used Cake Php, but i start thinking about trying igniter, as the documentation seems to be way more available. Having good info about our php framework is almost 50% of how we're going to like it, it's some time a pain to try to find out everything by yourself. Anyway, i still have to say it's two great framework ;)

Try Django !

I originally come from the PHP world but have been using Django (a python web framework) since a few months. I am really impressed by the quality, the features and the extensibility of this framework !

Concerning PHP, I am a big fan of CakePHP.

A useful start to have an overall view of PHP and non PHP (Ruby, Java, Python) frameworks :
http://www.therightsoft.com/softwaretechnologies/webframeworks

Good Review

Excellent review and very fair. I think you found the main differences in the MVC and configuration/convention differences. Also the ZF is extremely loosely coupled so that it's trivial to integrate most components (such as Zend_Search or Zend_Pdf) into another application.

One minor point is that the ZF also supports PHP arrays for configuration, though my personal preference is INI.

Regards,

Rob...

I would say configuration

I would say configuration through arrays is a rather good idea. During implementation of my application I've discovered standard PHP .ini parse function doesn't preserve variable values in a strict fashion:

ini_variable = true

results in value of $config->section->ini_variable to be === 1. This is certainly not what I want: for me 'true' means PHP true, 'false' PHP false, and '1' PHP 1 (or '1'). It really starts to matter when your code uses strict (===) comparisons (which, personally, I consider good PHP programming practice). So, I have written my own INI parsing method, and now I make a call:

$config = new Zend_Config(Argasek_Config_Ini::read($thisdir.'/cfg/whatever.ini'));

and convert array returned by ::read into object. Nice and clean.

Thanks Rob

Yeah, I just noticed PHP array support in the Zend_Config docs a few days back.

Another Framework

Can I suggest another framework?? Check out the Andromeda Database Framework. http://www.andromeda-project.org

Symfony Project is the best

i was in the same boat a while ago and my choice in the end was http://www.symfony-project.org/
* simple templating and helpers
* cache management
* smart URLs
* scaffolding
* multilingualism and I18N support
* object model and MVC separation
* Ajax support
* enterprise ready

i have used code igniter for many projects in the past but it really has limitations. Symfony is a entire development platform, debugging, etc. I could never go back to anything but Symfony now

Great Comparison

I'm forwarding this to Matthew so that we can go over some of your detailed view/controller/helper feedback. I hope you've gotten a chance to go over the new features in 1.5- many of these comparison points are addressed directly in this release. I can tell that you'll also be very interested in our next minor release. We'll be making a concerted effort to forge in to new, exciting, and entirely uncharted(!) territories with our AJAX/RIA support.

Thanks for taking the time...

Thanks for taking the time to review my review :)

In regards to view templating, I should probably qualify what really is a relatively minor difference for those reading this. With CakePHP, view wrapping works out-of-the-box, just save a default layout and your views are wrapped by the layout immediately. Layout wrapping in Zend actually isn't that difficult, only a few lines of code are required.

I think ZF users would benefit from an HTML helper, especially in light of increasing use of Ajax in web applications. I picture a lot of JS errors being avoided during development by having a helper generate HTML elements (unique ids, valid tags, proper nesting, etc). Heck, you could throw client-side validation (HTML, CSS, JS) into unit testing :)

I hope to have some time soon to take a closer look at 1.5. Thanks to you and Matthew for all of the great work on the Zend Framework.

My Clairvoyance

Ha! I just looked and the logo _is_ a flame. I guess it almost had to be, right?

Only problem is...

I hear CodeIgnitor enforces compact code formatting :)

Can you handle...

myFunction (arg1, arg2) {
    echo('Poke fun at Rob...');
}

Lovely

Nice. You working on a stand-up routine? :-)

My "rules" are many, varied and sometimes fuzzy, but they look a little like this:

1. If it's in oem code that I don't have to see or maintain...I probably don't care.
2. If any rendered output of the code referenced in #1 above is standards compliant - preferably XHTML 1.0 Strict for now - I definitely don't care.
3. If code is being written to create a functional prototype or proof-of-concept, then I don't care.
4. If any code anywhere is written by anyone other than myself or the people that work for me then I don't care.

This seems to fit within the scope of numbers 1 & 2. That's just how I roll.

Stand up, not religion :)

Just havin' a little fun. This routine has a very limited audience :)

I Hear You

I refer to my, um, fans as an "accidental audience". :-)

Timely...

I've been thinking about digging into the PHP framework scene now that I seem to be in that world full-time. Having come from the ColdFusion world, I might argue that Model-Glue is the new golden child among CF frameworks, but Fusebox still has its followers (not that this was the point you were trying to make :-).

As for config files, I don't think that my love for Ant would send me down the XML path, but I do like XML (or any other language-agnostic format) for its portability and even its readability with respect to static content like configuration metadata. Ant doesn't much care about the config file and I've used it with language-based config files as well as XML files.

Frankly, though, I may start with CodeIgnitor just because it's got the cooler name. It's logo probably even includes flames. How can you not go with flames?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <codeblock> <blockquote> <h1> <h2> <h3> <h4> <h5> <img>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Use the special tag [adsense:format:group:channel] or [adsense:flexiblock:location] to display Google AdSense ads.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.