Day 23: Another Look at symfony
Today is the last stop of our trip to the wonderful world of symfony. During these twenty-three last 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 this whole book.
What is symfony?
The symfony ~framework|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
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.
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 an 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|Settings~ for different ~environments|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:
app.ymlcache.ymldatabases.ymlfactories.ymlgenerator.ymlrouting.ymlschema.ymlsecurity.ymlsettings.ymlview.yml
The configuration files mostly use 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|Debug~
Main symfony Objects
The symfony framework provides quite a few core objects that abstract recurrent needs in web projects: the request, the response, the user, the logging, the routing, the mailer, 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 ##ORM##, the form framework also makes it easy to
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
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
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:
app:routescache:clearconfigure:databasegenerate:projectgenerate:appgenerate:modulehelpi18n:extractlistplugin:installplugin:publish-assetsproject:deploypropel:build --allpropel:build --all -and-loadpropel:build-formsdoctrine:build --alldoctrine:build --all -and-loaddoctrine:build --formspropel:build-modelpropel:build-sqlpropel:data-loadpropel:generate-adminpropel:generate-modulepropel:insert-sqltest:alltest:coveragetest:functionaltest:unit
You can also create your own tasks.
See you soon
Learning by Practicing
The symfony framework, as does any piece of software, has a learning curve. In the learning process, the first step is to learn from practical examples with a book like this one. The second step is to practice. Nothing will ever replace practicing.
That's what you can start doing today. Think about the simplest web project that still provides some value: a todo list manager, a simple blog, a time or currency converter, whatever... Choose one and start implementing it with the knowledge you have today. Use the task help messages to learn the different options, browse the code generated by symfony, use a text editor that has PHP auto-completion support like Eclipse, and refer to the reference guide to browse all the configuration provided by the framework.
Enjoy all the free material you have at your disposal to learn more about symfony.
The community
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:
- Subscribe to the user mailing-list
- Subscribe to the official blog feed
- Subscribe to the symfony planet feed
- Come and chat on the #symfony IRC channel on freenode
ORM
インデックス
Document Index
関連ページリスト
Related Pages
Day 1: Starting up the Project
Day 2: The Project
Day 3: The ~Data Model~
Day 4: The Controller and the View
Day 5: The Routing
Day 6: More with the Model
Day 7: Playing with the Category Page
Day 8: The Unit Tests
Day 9: The Functional Tests
Day 10: The Forms
Day 11: Testing your Forms
Day 12: The Admin Generator
Day 13: The User
Day 14: Feeds
Day 15: Web Services
Day 16: The ~Mailer~
Day 17: Search
Day 18: ~AJAX~
Day 19: Internationalization and Localization
Day 20: The Plugins
Day 21: The Cache
Day 22: The Deployment
Day 23: Another Look at symfony
Appendix B - License
Acknowledgments
日本語ドキュメント
Japanese Documents
2011/01/18 Chapter 17 - Extending Symfony
2011/01/18 The generator.yml Configuration File
2011/01/18 Les tâches
2011/01/18 Emails
2010/11/26 blogチュートリアル(8) ビューの作成
リリース情報
Release Information
- 2.0 : 2.0.10(2011/02/06)
Symfony2日本語ドキュメント - 1.4 : 1.4.16(2011/12/13)
Changelog
