Symfony 2.0 Intro

8,920 views

Published on

A tech talk on Symfony 2.0 for San Francisco PHP/Symfony Meetup at CBS Interactive.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,920
On SlideShare
0
From Embeds
0
Number of Embeds
32
Actions
Shares
0
Downloads
124
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Symfony 2.0 Intro

  1. 1. Dustin Whittle - @dustinwhittle
  2. 2. Symfony-Reloaded.org
  3. 3. What is Symfony? Symfony is a PHP 5.3 full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easier to maintain websites with PHP.
  4. 4. What is new in Symfony?
  5. 5. Everything!
  6. 6. It is Symfony not symfony
  7. 7. A fresh look at Symfony Symfony2 is a complete rewrite of symfony 1.x Fabien Potencier has been working on Symfony2 for years - almost as long as symfony 1.x Focus is on Performance, Flexibility, and Extensibility Cleaner implementations with less magic
  8. 8. Coming from symfony 1.x If you are launching today, use symfony 1.4 No simple upgrade path to Symfony 2.0 If you are launching in six months use Symfony 2.0 Current release is alpha
  9. 9. The Foundation PHP 5.3.2+ required Leverage the latest features for a clean and simple API Building on the shoulders of giants ORM: Doctrine2 or Propel Email: SwiftMailer Testing: PHPUnit Logging: Zend Framework
  10. 10. The Core The Kernel Bootstraps configuration + loads bundles The Bundles Almost all functionality is a bundle in Symfony2 FoundationBundle, DoctrineBundle, DoctrineMongoDBBundle, PropelBundle, SwiftmailerBundle, TwigBundle, ZendBundle Use bundles to share features between projects
  11. 11. The Core Dependency Injection Container Configure dependencies in YAML or XML Only use what you need when you need it The Request Handler Converts a request into a response Can be highly optimized depending on requirements Event Dispatcher
  12. 12. Take the quick tour
  13. 13. symfony-reloaded.org/learn
  14. 14. Getting started Download the sandbox http://github.com/symfony/symfony-sandbox
  15. 15. Doctrine 2.0 Doctrine2 features fully integrated Database Abstraction Layer Object Relational Mapper Rewritten from scratch to focus on performance Less magic
  16. 16. Configuring Doctrine DBAL doctrine.dbal: default_connection: default connections: default: driver: PDOSqlite dbname: Symfony user: root password: null host: localhost port: ~ path: %kernel.data_dir%/symfony.sqlite event_manager_class: DoctrineCommonEventManager configuration_class: DoctrineDBALConfiguration wrapper_class: ~ options: []
  17. 17. Using Doctrine Connections class MyController extends DoctrineController { public function indexAction() { $conn = $this->getDatabaseConnection('default'); // ... } }
  18. 18. Configuring Doctrine ORM doctrine.orm: default_entity_manager: default cache_driver: apc # array, apc, memcache, xcache entity_managers: default: connection: default
  19. 19. Creating Doctrine Entities /** @Entity */ class User { /** * @Id @Column(type="integer") * @GeneratedValue */ private $id; /** @Column(type="string", length=255) */ private $name; public function getId() { return $this->id; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } }
  20. 20. Using Doctrine Entities class MyController extends DoctrineController { public function indexAction() { $em = $this->getEntityManager(); $query = $em->createQuery('select u from MyBundle:User u'); $users = $query->execute(); // ... } }
  21. 21. Using Doctrine Entities class MyController extends DoctrineController { public function indexAction() { $em = $this->getEntityManager(); $qb = $em->createQueryBuilder() ->select('u') ->from('MyBundle:User', 'u'); $query = $qb->getQuery(); $users = $query->execute(); // ... } }
  22. 22. Console commands implemented for improved developer workflow: Ensure production settings Clear metadata, query and result cache Load data fixtures Create and drop configured databases Generate entities from mapping information Generate new skeleton entities Generate skeleton entity repository classes Convert mapping information between formats
  23. 23. Doctrine 2.0 & MongoDB Doctrine 2.0 supports Mongodb MongoDB Object Document Mapper Transparent persistence to MongoDB Same architecture as ORM Map a class as an entity and document
  24. 24. Configure Doctrine ODM doctrine_odm.mongodb: default_document_manager: default cache_driver: array document_managers: default: connection: mongodb connections: mongodb: server: localhost/somedatabase
  25. 25. Mongo Documents /** @Document */ class User { /** * @Id */ private $id; /** @String */ private $name; public function getId() { return $this->id; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } }
  26. 26. Using Doctrine/MongoDB class MyController extends DoctrineController { public function createAction() { $dm = $this->getDocumentManager(); $user = new User(); $user->setName('Jonathan H. Wage'); $dm->persist($user); $dm->flush(); // ... } }
  27. 27. Using Doctrine/MongoDB class MyController extends DoctrineController { public function indexAction() { $dm = $this->getDocumentManager(); $query = $dm->createQuery('User') ->where('username', 'jwage'); $user = $query->getSingleResult(); // ... } }
  28. 28. Symfony 2.0 Forms
  29. 29. Symfony 2.0 Testing Uses PHPUnit 3.5.x Adds custom web client + crawler
  30. 30. Symfony 2.0 Caching Leverages ESI for ideal caching on the edge Easy integration with any reverse proxy cache
  31. 31. Finding Documentation Symfony Official Site http://symfony-reloaded.org The State of Symfony slides http://www.slideshare.net/fabpot Join the symfony-users@googlegroups.com
  32. 32. Want to contribute? http://github.com/symfony/symfony

×