CakePHP and Symfony

There are many frameworks out there that have a good deal of uses to them. In this post, the focus is on CakePHP vs Symfony. Does this mean one will be a winner over the other? Not really. I will only present what I have come to find in each of these frameworks and how I have used them in different ways.

Since this will be a comparison, most of the ideas will revolve around the tutorials that each camp has created. Plus, I will be only looking at the latest stable versions, so they are:
CakePHP: 1.2.1.8004
Symfony: 1.2

Each have their own tutorials, and they are at the following:
Symfony: Jobeet Tutorial, using Propel.
CakePHP: CakePHP Blog

First off, about the tutorials.
I really do think that Symfony has a better tutorial. It is a lot more intensive and sometimes confusing, which means it also goes more in depth about what this framework can do, and how to do it. This tutorial also brings in a good deal of real world dilemmas.

CakePHP’s blog tutorial is just a standard blog tutorial, which everyone seems to have anymore. It is a good tutorial, and it does show off some real good aspects of the framework, but it really does lack some of the “gotchas” that would really happen in the real world.

Installation Process and Upgrade
Symfony – Getting Symfony is pretty easy. You can download it from the site in a “sandbox” form. It is pretty easy and able to do much right from the download. But what makes this framework so wonderful about getting it, is that you can use PEAR to download it. By following the detailed installation instructions, there are a few different ways to install this. If you have the PEAR libraries, it makes it very easy to install and upgrade.

CakePHP – Getting CakePHP is also easy. While it does not have a PEAR installation path, the zip file is available in many forms, like .zip, or .gz, bz2, or .dmg. After you unzip the file, just plop it in the web accessible document root. It will work right out of the box provided on most systems. It is supposed to work right away with mod_rewrite, so certain Windows systems may have issues. (However, I have loaded it on a Windows Vista system and it worked ok, so take that for what it is worth). The directory structure allows it to work right away as is. However, the webroot app can be moved outside the normal directory structure to make a different configuration. Upgrading can be done as well, usually by overwriting the /cake directory.

But as with everything, always follow directions on upgrading. Very important.

Basic Ideals Behind the Framework
Symfony – Using a basic MVC (Model-View-Controller) design theory, it really does separate the logic portions of the application. By using the built in view, it keeps the majority of the PHP out of the HTML area. The models use more of a YAML approach to build the data objectivity. YAML (YAML Ain’t a Markup Language, morphed from Yet Another Markup Language). It can use Propel or Doctrine to help in this. The Jobeet tutorial I used was the Propel version. The controller is a standard idea of what you would expect in a controller.

CakePHP – Uses a MVC design theory, and really follows the same patterns. The real strength of CakePHP, at least to me, is it does not mess around with another version of data markup, like YAML. Some people like it, I do not prefer it. So to me this is better. However, the model also provides a real easy way to provide data validation for each row in the table. By using basic PHP concepts, you can set up validation for inserts and/or updates. The view is a little less robust than the Symfony version. While it does help with different pages/views, the framework does have a little too much reliance on php generated code. However, it does have excellent helpers to help generate HTML, forms, tables, etc.

Routing and Fancy URLs
Symfony – By updating the file: apps/frontend/config/routing.yml (yes it uses another YAML format) you can route certain calls to certain pages. However, this makes it real easy to create Fancy URLs in which the URL actually has some real data in it instead of something like : ‘jobs/2/34’.

CakePHP – In order to create Fancy URLs, CakePHP needs to have the default routes updated. While it is not as easy as it is in Symfony, it is possible. By using the detailed instructions in the Cookbook, you can set this up to have the nice URLs.

Command Line Interface Utilities
Symfony – Now while this is not an instructional post on how to use each CLI, I must say, I like the Symfony version a lot better. While it is clean and real forthcoming, there is a lot you can do with it. Combine that with the Propel and you have a really good CLI tool to help with the application.

CakePHP – The CLI in CakePHP leaves a little to be desired. While it is very helpful in creating the Models, the Controllers, and the Views, it really does not do as much. But for CakePHP this is actually ok. There are a lot of things to do with the CLI, but not as much as Symfony has.

Configuration
Symfony – Symfony seems to thrive on configurations for some reason. There is a whole directory dedicated to just config files. To me this seems a bit of overkill to do it this way. However, with the way Symfony is laid out, it works this way. There are different things to configure, and following the instructions is key. Especially since these files are read from top to bottom, so if you have a custom config in the routes after the default entry, it will never find the custom one.

CakePHP – There is also a full directory dedicated to configurations as well, but less files to parse through. Some may say this is a bad thing, some may say this is a good thing. The main files to look at are the core.php and database.php files. The routes.php file is also useful, but all in all, less config files to deal with.

Naming Conventions
Instead of separating this area, it is important to note that with each framework, there is a reason behind the madness with naming conventions. By adhering to these conventions, the framework works a lot better and can do a lot more.

In Symfony there is more leeway with file names, tables, etc.

In CakePHP they are a bit more strict, but these conventions can also be bent to suit the needs.

Core Components
Symfony – There is a good deal of components in this framework, and they all have a set purpose. Instead of matching each one as a 1:1 deal, it is important to go over the usability of these components. In Symfony, there are good ones to help paginate, create sessions, scaffold an application and even do security. Using these is easy, and this is one area where both frameworks excel.

CakePHP – Again, this is a great area for both frameworks. While in CakePHP, the components are not limited to the core ones, but can be extended (as in Symfony), they are very useful in helping create the application. These components are very helpful and can be a boon to even the novice programmer.

Both of these frameworks use these components to help speed the application up while not giving in to shoddy work.

Testing
Symfony – The great thing about Symfony, is that it has a built in testing platform. The testing platform it includes is Lime. This is a great boost to development. Now while writing the application, you can actually write the test first, then the application to make sure you know which area needs more attention. Both Unit and Functional testing is handled, and can work with others like PHPUnit and Selenium.

CakePHP – one of the great things about this framework, is that you can choose which testing platform to use. The drawback to that is, you do not get a testing platform with the package. However, it is encouraged to use SimpleTest to do this. Installation is another step, but it helps to test the application. Writing the tests is a little more than what it takes in Symfony, however, I also believe that it does testing better than Symfony.

Security
Here is a question for any and all frameworks. How secure is it? well this can be answered with the following question:
How secure are you writing this application?

Even though Symfony and CakePHP provide good methods, components and helpers to handle securing your application, you have to use these, and use them correctly. Both proved ACL implementations, data validation and sanitation and much more to help secure the app. For any one to make a statement that one framework is more secure than the other, is just not getting the point of security.

Documentation
Symfony – By far, this is the more documented framework. I have been able to find a ton of information on Symfony questions. The documentation in the cookbook is solid, and the tutorial is better than anything I have seen from other frameworks. There are other groups, IRC channels and other avenues to explore to help you get the info you need.

CakePHP – This framework is still coming of age. So the documentation is not always complete and not always found right away. There are groups, IRC channels and other avenues to get this information, just not as plentiful. However, that will change very shortly. With a stronger emphasis on community events and community submissions, this framework could easily have a plethora od documentation avenues by next year.

**NOTE: The following is based on my own personal experience.
As mentioned in the comments below, CakePHP does have stats to show it is bigger and more popular than Symfony. Please see Nate’s comments below for the links.

Community
Symfony – With many sites already using Symfony, the community is growing like wildfire. It was already a very abundant community, with many people helping and contributing. As with every open source project, it is only as strong as its community, which is very active.

CakePHP – This is the up and comer. Not quite as widespread as Symfony, but it has it very loyal followers. There are many ways that a community member can help out (and not just by donating), and this community is really rising fast to help meet the demand for more events and more documentation.

Final Analysis
While I will not give a clear cut answer as to which is the better framework, because the best solution is the solution that will meet the needs of the business/client/etc. Sometimes that may be Symfony, sometimes it may be CakePHP. Sometimes it may just be .ASPX. But there is no real clear cut winner in my mind.

I have used both frameworks to develop applications. Some of them huge, some of them small. I find CakePHP easier to start up from the ground up. And I find the extensibility of Symfony really helpful in certain apps that require a lot of redundant user input. Both frameworks are great. I would use both of them all the time for different things.

Which also means that I am no expert in either one. Since I spend time in both frameworks, I know what I like and do not like about each of them. I would also wager to say that no one is really an expert in either framework, unless you are the main developer of that project. What I am presenting is the different aspects I have found from my development standpoint. Some may see things missing in this list, which I am sure there are. These are some of the things to decide when trying to figure out if a framework will help you. Some developers also are of the opinion that no framework is good and would rather develop from scratch. That is fine too. Remember that the best solution to the problem, is the solution that solves the main crux of the problem.

This Post Has 12 Comments

  1. Ismael

    Interesting post, i think that is not a bad idea know how work with both frameworks, because in php we have to use the best solution in each problem.

    cakephp maybe best framework for north americans (is most famous there) and symfony meybe best framework for europeans (it comes from europe).

    I am from panama and i already use the europe way to do things, but i am going to give a try to cake.

    so, i think that the only winner here are the developers and the community.

  2. stephen

    Thank you for the comment. When the community gets involved, it is always the developer who wins. As CakePHP grows up a little more, there will be more talk of it. Symfony is a more mature framework, and has the benefit of a lot of user submitted documentation.

  3. dr. Hannibal Lecter

    “Not quite as widespread as Symfony”

    According to Google, that’s not quite true.. Where did that info come from?

  4. stephen

    Google may give some info on it. I may have used the wrong words in writing this. Don’t get me wrong, I love CakePHP, and love reading all the blogs about CakePHP. In my experience I have seen more corporate projects leaning towards Symfony than they do towards CakePHP.

    I guess I should have clarified that a bit more.

  5. stephen

    Nate, thank you for that information. As mentioned above, I should have clarified that this is based wholly on my experience and not a scientific study whatsoever.

    I am going to check those out.

  6. jfk

    Hello,
    I found your comparison intelligent and usefull. I have been using symfony since 1.0, and I am starting to use cake.

    My opinion is that symfony has more features. The model generation is great, just needs a correct schema and here you go.

    But, the reason I now learn cake is because, and I think this is worth mentioning, Symfony changes too much.
    I mean, have a look at Symfony 2.0 … it nearly has nothing to do with S. 1.2
    If I am to maintain a website, and my framework makes 180 degrees turns each 6 month, it is not for me I think. This is the major problem with Symfony.
    Call me paranoid but I would say they do this intentionnally in order to make more trainings (= more income for sensio)

  7. Vasilij

    Very nice post πŸ™‚ I can say that i am on cake almost 2 years , and i do not think that Symfony is so greate , after few hours on Symfony two bugs were found by me . Moreover first i found out Cake only later Symfony πŸ™‚ i am from Eurpoe so Ismael i do not think that EU is mostly prefer symfony πŸ™‚ YAML is very nice for optimisation your requests to DB , but i think that using YAML structure to define smth in framework core is just waste of your time .

  8. James

    @jfk: i have to agree on that, it’s like they are developing the framework in their own microcosmos sometimes, when you’re working on some other stuff not always related to symfony or php and you come back to the website 6 months later, it’s nearly like they changed everything, i have plenty of apps stuck on sf 1.0 and i don’t think i’ll try to update them to 1.3

  9. Rafeeq

    I have been working in symfony for the last 2 years(version 1.1).I think total structure of symfony is somewhat heavy,more configurable than others.So probably people choose symfony for big projects.but symfony made drastic changes for new versions.New versions are coming for very short periods!.So we cannot upgrade easily to new versions.symfony 1.0 and 1.4 are 2 different product rather than a version.That much changes.Now they will plan to release symfony 2.0! yet another cakePHP πŸ™‚

  10. lordraven

    Symfony it`s great but if you starting with frameworks you should start with CakePHP is much easer to learn than symfony.

  11. Rajesh Yadav

    A drawback which I have seen in symfony till now is that, when you try to alter a table by adding new columns in your schema.yml, It flushes the data from the table and gives you an altered table with no data. This is really bad, if you don’t know this behavior and move ahead altering the table. Though Symfony provider propel-dump-data to handle alter tables, but it is still quite buggy and slow for big databases.

Leave a Reply