Symfony is an MVC framework, along the lines of Ruby on Rails, but based on PHP5. It is widely used, including yahoo bookmarks:
and the beta of the new version of del.icio.us:
So why did I choose symfony as a framework for web development at Kent, as opposed to the many others (for example cakePHP and codeIgniter)? There are lots of reasons, as I’ll show later. But the three most important are:
- it’s well documented
- there’s a good and helpful user community
- it’s very powerful
Documentation? No, don’t need that. Well clearly that’s what a lot of frameworks seem to think. Although most frameworks – and certainly cake and codeigniter – have great communities, their documentation isn’t always great. For example, cake has a kind of ‘getting started’ document and then sort of leaves the rest up to you. Fine if you want to do basic stuff, but not so great if you want more.
The key thing with a good community, apart from helpful advice on forums, is the availability of plugins. Symfony has loads of those, as you can see here http://trac.symfony-project.com/wiki/SymfonyPlugins. Many are pretty esoteric, but a lot are really useful, such as a really nice user security plugin called sfGuard.
As for being powerful, the thing you notice first off with symfony is that it’s only compatible with php5. Only? That seems odd. Brave almost. But surely they could’ve tweaked things a little to get php4 support? Once you take a look under the hood, you realise that symfony is totally object-oriented. Inheritance, mixins, overloading, public/private/protected. It’s all there, beautifully structured. What’s great about the use of OOP and php5 is that symfony uses autoloading, so a lot of classes (including plugins) are easily available without lots of includes all over the place.
Less is more
OK so symfony sounds complicated, and in many ways that’s true. The real power of the framework comes from its flexibility. There are dozens of configuration files which let you change many aspects of how your application works, from how the urls appear to fine details in a pre-generated backend system. This power creates complexity. But really, any good php developer ought to be able to cope with this kind of thing.
But the power of the system also lies in its potential to bypass many parts of symfony altogether. For example, you don’t have to use the built-in database abstraction layers. Just use anything you want instead, including (heaven help us!) raw SQL. You don’t have to use the built-in scriptaculous ajax methods (but why wouldn’t you).
One of the main reasons for using a framework is to give your code some structure, rather than the usual ordered chaos of a hacked-together website. That’s all very well, particularly for big projects. But a real plus for many developers is the ability to produce web applications quickly. symfony can help there too.
One feature that really helped me recently was the admin generator. Beautiful. I basically made a mini-phpMyAdmin interface in about 5 mins. Add to that the sfGuard plugin for authentication and authorization, and in about 10 mins you have a fully-featured admin system. And it actually looks good too.
There are also great time-savers for things that sane developers hate. Things like forms and input validation.
symfony is a great way to save time and develop good, maintainable code. It’s a powerful framework, and is surely set to grow, particularly now that yahoo have adopted it for a couple of applications. It’s not perfect, but offers a huge amount of power and flexibility, and speeds up application development significantly.