This post was published as part of the symfony 2008 advent calendar. As this tutorial might have been updated since then, you are advised to read the last version from the symfony 1.2 documentation (for Propel or Doctrine).

Today is the last stop of our trip to the wonderful world of symfony. During these twenty-three days, you learned symfony by example: from the design patterns used by the framework, to the powerful built-in features. You are not a symfony master yet, but you have all the needed knowledge to start building your symfony applications with confidence.

As we wrap up the Jobeet tutorial, let's have another look at the framework. Forget Jobeet for an hour, and recall all the features you learned during the last three weeks.

What is symfony?

The symfony framework is a set of cohesive but decoupled sub-frameworks, that forms a full-stack MVC framework (Model, View, Controller).

Before coding head first, take some time to read the symfony history and philosophy. Then, check the framework prerequisites and use the check_configuration.php script to validate your configuration.

Eventually, install symfony. After some time you will also want to upgrade to the latest version of the framework.

The framework also provides tools to ease deployment.

The Model

The Model part of symfony can be done with the help of the Propel ORM. Based on the database description, it generates classes for objects, forms, and filters. Propel also generates the SQL statements used to create the tables in the database.

The database configuration can be done with a task or by editing a configuration file. Beside its configuration, it is also possible to inject initial data, thanks to fixture files. You can even make these files dynamic.

Propel objects can also be easily internationalized.

The View

By default, the View layer of the MVC architecture uses plain PHP files as templates.

Templates can use helpers for recurrent tasks like creating a URL or a link.

A template can be decorated by a layout to abstract the header and footer of pages. To make views even more reusable, you can define slots, partials, and components.

To speed up things, you can use the cache sub-framework to cache a whole page, just the action, or even just partials or components. You can also remove the cache manually.

The Controller

The Controller part is managed by front controllers and actions.

Tasks can be used to create simple modules, CRUD modules, or even to generate fullly working admin modules for model classes.

Admin modules allows you to built a fully functional application without coding anything.

To abstract the technical implementation of a website, symfony uses a routing sub-framework that generates pretty URLs. To make implementing web services even easier, symfony supports formats out of the box. You can also create your own formats.

An action can be forwarded to another one, or redirected.

Configuration

The symfony framework makes it easy to have different configuration settings for different environments. An environment is a set of settings that allows different behaviors on the development or production servers. You can also create new environments.

The symfony configuration files can be defined at different levels and most of them are environment aware:

The configuration files mostly uses the YAML format.

Instead of using the default directory structure and organize your application files by layers, you can also organize them by feature, and bundle them in a plugin. Speaking of the default directory structure, you can also customize it according to your needs.

Debugging

From logging to the web debug toolbar, and meaningful exceptions, symfony provides a lot of useful tools to help the developer debug problems faster.

Main symfony Objects

The symfony frameworks provides quite a few core objects that abstract recurrent needs in web projects: the request, the response, the user, the logging, the routing, and the view cache manager.

These core objects are managed by the sfContext object, and they are configured via the factories.

The user manages user authentication, authorization, flashes, and attributes to be serialized in the session.

Security

The symfony framework has built-in protections against XSS and CSRF. These settings can be configured from the command line, or by editing a configuration file.

The form framework also provides built-in security features.

Forms

As managing forms is one of the most tedious task for a web developer, symfony provides a form sub-framework. The form framework comes bundled with a lot of widgets and validators. One of the strength of the form sub-framework is that templates are very easily customizables.

If you use Propel, the form framework also makes it easy to generate forms and filters based on your models.

Internationalization and Localization

Internationalization and localization are supported by symfony, thanks to the ICU standard. The user culture determines the language and the country of the user. It can be defined by the user itself, or embedded in the URL.

Tests

The lime library, used for unit tests, provides a lot of testing methods. The Propel objects can also be tested from a dedicated database and with dedicated fixtures.

Unit tests can be run one at a time or all together.

Functional tests are written with the sfFunctionalTest class, which uses a browser simulator and allows symfony core objects introspection through Testers. Testers exist for the request object, the response object, the user object, the current form object, the cache layer and the Propel objects.

You can also use debugging tools for the response and forms.

As for the unit tests, functional tests can be run one by one or all together.

You can also run all tests together.

Plugins

The symfony framework only provides the foundation for your web applications and relies on plugins to add more features. In this tutorial, we have talked about sfGuardPlugin, sfFormExtraPlugin, and sfTaskExtraPlugin.

A plugin must be activated after installation.

Plugins are the best way to contribute back to the symfony project.

Tasks

The symfony CLI provides a lot of tasks, and the most useful have been discussed in this tutorial:

You can also create your own tasks.

Acknowledgements

Writing a tutorial like Jobeet is both exciting and exhausting. You spend hour after hour trying to figure out how to convey your message, how to explain concepts, and how to provide simple but meaningful and reusable examples.

Writing such a big tutorial is just impossible to do without people around supporting you along the process. For Jobeet, I (Fabien Potencier) had the chance to benefit from top notch reviewers. They are all part of the symfony adventure and I want to thank them all for the time they spent on the Jobeet project.

Kris Wallsmith, our community manager and soon-to-be-announced symfony 1.3 release manager, took the time to proof-read my far-from-perfect English prose. As this tutorial was published on a day-to-day basis, and because I live in France, and he in the US, he got up very early every single morning this month, including weekends, to read and fix each tutorial.

Stefan Koopmanschap, one of the most active symfony evangelist, took the responsibility to run the Subversion repository. Thanks to his work, you can view the code and start reading the tutorial for any day.

Fabian Lange, the symfony 1.2 release manager, and the symfony "guy", read the book with a Windows perspective and tried to be our newbie reader. On a side note, he recently bought a Mac so we need someone else to take on the "Windows guy" responsibility.

Jonathan Wage, the Doctrine lead developer, took the time to create a Doctrine edition of the tutorial. Thanks to his great efforts, you can choose between Propel or Doctrine as your main ORM for symfony, and still enjoy the same tutorial.

Pascal Borreli, an online barfly on the symfony french IRC channel, and the most friendly symfony community member, read the tutorial chapter after chapter at speed light. His continuous support and his kind words kept me in good mood to write this tutorial from start to finish.

See you soon

Before you leave, I would like to talk about one last thing about symfony. The framework has a lot of great features and a lot of free documentation. But, one of the most valuable asset an Open-Source can have is its community. And symfony has one of the most amazing and active community around. If you start using symfony for your projects, consider joining the symfony community:

Joyeux Noël !

Published in #Tutorials