SlideShare uma empresa Scribd logo
1 de 13
Learning Symfony by practice
SYMFONY2
PHP Framework
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
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)
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?
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.
Twig template example
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
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.
Routing
acme_demo.article.show
        path:/articles/{culture}/{year}/{title}.{_format}
        defaults: { _controller: AcmeDemoBundle:Article:show, _format: html }
        method: GET
        requirements:
                culture: en|fr
                _format: html|rss
                year:    d+
● Earlier routes always wins
● Use YAML format.
● Routing name
– {name of the bundle without 
“Bundle”}.{name of the 
controller without “Controller”}.
{name of the action without 
“Action”}
– acme_demo.article.show
Symfony application structure
● app:/ the application configuration
● src:/ the project PHP code
● web:/ web root directory, all static content
● vendors:/ the third-party dependencies
Bundle structure
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.
Symfony workshop
● DoubleCommentBundle
● Entities: Post, PostComment
● Form: PostFormType, PostFormType
● Bundle, Controller, Routing, Twig, Services

Mais conteúdo relacionado

Destaque

E uam male-fin_hr
E uam male-fin_hrE uam male-fin_hr
E uam male-fin_hr
Havas PR
 
Me llamo tarianna
Me llamo tariannaMe llamo tarianna
Me llamo tarianna
lakahaywood
 
Court white paper
Court white paperCourt white paper
Court white paper
Havas PR
 
The circulatory system
The circulatory systemThe circulatory system
The circulatory system
Espirituanna
 
Dse control prevention_in_dental_1_
Dse control prevention_in_dental_1_Dse control prevention_in_dental_1_
Dse control prevention_in_dental_1_
Espirituanna
 
The sisterhood
The sisterhoodThe sisterhood
The sisterhood
Havas PR
 
E ukenmore fut_home_05lowres
E ukenmore fut_home_05lowresE ukenmore fut_home_05lowres
E ukenmore fut_home_05lowres
Havas PR
 
E uam male-fin_lr
E uam male-fin_lrE uam male-fin_lr
E uam male-fin_lr
Havas PR
 
Skeletal system lab
Skeletal system labSkeletal system lab
Skeletal system lab
Espirituanna
 
Court white paper
Court white paperCourt white paper
Court white paper
Havas PR
 

Destaque (19)

Medellin primaveral
Medellin primaveralMedellin primaveral
Medellin primaveral
 
E uam male-fin_hr
E uam male-fin_hrE uam male-fin_hr
E uam male-fin_hr
 
Me llamo tarianna
Me llamo tariannaMe llamo tarianna
Me llamo tarianna
 
8389 work 1
8389 work 18389 work 1
8389 work 1
 
Icai 17.02.2017 Taxation of foreign remmitances
Icai 17.02.2017 Taxation of foreign remmitancesIcai 17.02.2017 Taxation of foreign remmitances
Icai 17.02.2017 Taxation of foreign remmitances
 
Court white paper
Court white paperCourt white paper
Court white paper
 
The circulatory system
The circulatory systemThe circulatory system
The circulatory system
 
Luis carlos martinez massa y luisa y fernanda
Luis carlos martinez massa y luisa y fernandaLuis carlos martinez massa y luisa y fernanda
Luis carlos martinez massa y luisa y fernanda
 
Cloud computing (1)
Cloud computing (1)Cloud computing (1)
Cloud computing (1)
 
Sound Sound - Parent info night presentation
Sound Sound - Parent info night presentationSound Sound - Parent info night presentation
Sound Sound - Parent info night presentation
 
Dse control prevention_in_dental_1_
Dse control prevention_in_dental_1_Dse control prevention_in_dental_1_
Dse control prevention_in_dental_1_
 
The sisterhood
The sisterhoodThe sisterhood
The sisterhood
 
E ukenmore fut_home_05lowres
E ukenmore fut_home_05lowresE ukenmore fut_home_05lowres
E ukenmore fut_home_05lowres
 
데이빗라인트레이닝미팅
데이빗라인트레이닝미팅데이빗라인트레이닝미팅
데이빗라인트레이닝미팅
 
Bs presentation new
Bs presentation newBs presentation new
Bs presentation new
 
Dental care journal
Dental care journalDental care journal
Dental care journal
 
E uam male-fin_lr
E uam male-fin_lrE uam male-fin_lr
E uam male-fin_lr
 
Skeletal system lab
Skeletal system labSkeletal system lab
Skeletal system lab
 
Court white paper
Court white paperCourt white paper
Court white paper
 

Semelhante a Learning Symfony2 by practice

An introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersAn introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developers
Giorgio Cefaro
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
Fabien Potencier
 
Starting with Symfony2
Starting with Symfony2Starting with Symfony2
Starting with Symfony2
Kevin Bond
 

Semelhante a Learning Symfony2 by practice (20)

An introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersAn introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developers
 
PhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 PluginPhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 Plugin
 
Symfony, Oxid, Composer
Symfony, Oxid, ComposerSymfony, Oxid, Composer
Symfony, Oxid, Composer
 
PHP Frameworks and Symfony
PHP Frameworks and SymfonyPHP Frameworks and Symfony
PHP Frameworks and Symfony
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
 
AtoM feature development
AtoM feature developmentAtoM feature development
AtoM feature development
 
The use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogThe use of Symfony2 @ Overblog
The use of Symfony2 @ Overblog
 
IBM Connect2014 JMP106
IBM Connect2014 JMP106IBM Connect2014 JMP106
IBM Connect2014 JMP106
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
Symfony2 as an api
Symfony2 as an apiSymfony2 as an api
Symfony2 as an api
 
25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboards25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboards
 
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
 
Starting with Symfony2
Starting with Symfony2Starting with Symfony2
Starting with Symfony2
 
Symfony2 components to the rescue of your PHP projects
Symfony2 components to the rescue of your PHP projectsSymfony2 components to the rescue of your PHP projects
Symfony2 components to the rescue of your PHP projects
 
Microservices
Microservices Microservices
Microservices
 
Symfony framework-An overview and usability for web development
Symfony framework-An overview and usability for web developmentSymfony framework-An overview and usability for web development
Symfony framework-An overview and usability for web development
 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19
 
The distinct advantages of using PHP-Symfony Framework
The distinct advantages of using PHP-Symfony FrameworkThe distinct advantages of using PHP-Symfony Framework
The distinct advantages of using PHP-Symfony Framework
 
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + FlexWhat is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Learning Symfony2 by practice