2. About:
I part: Symfony in
theory
● Composer
● Symfony ECO system
(twig, doctrine2, assetic)
● DI or what is symfony
service container?
● Symfony configuration
● Routing
● Bundle and it's structure
● Symfony best practices
discovered using symfony
II part: Symfony in
practice. Workshop.
● DoubleBlogBundle
● What we try in practice:
– Bundle
– Controller
– Routing
– Twig
– Entities
– Forms
– Services and DI
3. What is SYMFONY2?
● Symfony2 is a reusable set of standalone, decoupled and
cohesive PHP components.
● Symfony2 is made from components – bundles.
● Symfony2 is also a full-stack framework.
● Compliant with PSR-0 , PSR-1, PSR-2, PSR-3.
● Very active community
● Most popular PHP project on github.com (873 contributors)
4. Composer
● What is composer? Dependency Manager for PHP
● composer.json http://pastebin.com/iKRtNwq8
● composer.lock
● https://packagist.org/ and http://knpbundles.com/
● When use composer update and composer install
commands?
5. Symfony ECO system
● Twig - the flexible, fast, and secure template engine for
PHP
● Assetic – assets + filters.
– Assets is all your application static content (css, js, images)
– Filters (LESS, SASS or CoffeeScript)
● Doctrine 2 – is library for persisting and reading
information from your database.
7. Dependency injection component
● What is DI?
– is a software design pattern that allows the removal of hard-coded
dependencies and makes it possible to change them, whether at
run-time. Dependency injection means giving an object its instance
variables. Really. That's it.
● What is Service container?
– A Service Container (or dependency injection container) is simply a
PHP object that manages the instantiation of services (i.e. objects).
● We will learn more in second part.
● http://knpuniversity.com/screencast/dependency-injection/services
8. Symfony configuration
● 1. Different formats for configuration: xml, yaml, ini, php,
annotations
● 2. The application in general using Yaml files.
● 3. Routing using Yaml files or annotations.
● 4. Service definitions using XML files or yaml.
● 5. Documents and entities using annotations.
● 6. Documents and entity validation using annotations.
12. Symfony2 best practices
● Keep controller slim
– controller code is not testable
– all business logic goes to services
● To keep it slim
– use services.
– event listeners
– Custom form handlers?
● If you want to access global PHP variables like $_POST, $_GET, $_COOKIES values use Symfony
Request object.
– Awoid use $request->get(‘key’).
– use $request->query->get(‘key’) or $request->request->get(‘key’)
● When choosing ids for services, use only underscores and lowercase characters. Optionally provide
namespacing using dots.
● The service id for the service of class MailManager inside the MatthiasAccountBundle may be
matthias_account.mail_manager.
● Awoid inject Symfony service container. Just in special cases.
● Awoid inject Request and Security components. Just in special cases.