This document introduces several new features of Symfony2 including the Dependency Injection Container, form framework, and Doctrine2 integration. It discusses how the Dependency Injection Container can be used to define and load services, provides an example of creating a Twitter service, and explains how to enable extensions. It also briefly outlines using the form framework and integrating Doctrine2's DBAL, ORM, and command lines.
2. Symfony2 introduced a lot a new features,
let’s discover some of them:
• Dependency Injection Container
• The form framework
• Doctrine2 integration
3. Dependency Injection Container
• Dependency Injection Container
–a way to organize dependencies
–Define services
services:
zend.translator:
class: User
arguments: [@user.storage]
user.storage:
class: SessionStorage
5. • Create your own service
–Symfony2 offer a simple and effective way to create
services
–It’s called an extension
–An extension can receive some configuration parameter
from the application config.yml file (i.e. databases
connections, passwords, etc.)
6. • Create your own service
–Define your services:
# src/Bundle/TwitterBundle/Resources/config/user.yml
parameters:
twitter.username: ~
twitter.password: ~
services:
twitter:
class: Twitter
arguments: [%twitter.username%, %twitter.password%]
7. • Create the extension class
# src/Bundle/TwitterBundle/DependencyInjectionContainer/TwitterExtension.php
8. • Load your service
# src/Bundle/TwitterBundle/DependencyInjectionContainer/TwitterExtension.php
9. • Enable the extension
–Add these lines in the application config.yml file:
# hello/config/config.yml
twitter.twitter:
username: noelguilbert
password: mysecretpassword