Upgrade to Pro — share decks privately, control downloads, hide ads and more …

An Introduction to Symfony2

An Introduction to Symfony2

A simple introduction to Symfony2 for LoneStarPHP11

F670cde47cb2f445575ac4e0e3c7a889?s=128

Geoffrey Tran

July 03, 2012
Tweet

More Decks by Geoffrey Tran

Other Decks in Programming

Transcript

  1. !Symfony2:!It’s!Play!Time! @geoffreytran! www.linkedin.com/in/geoffreytran!

  2. What!is!Symfony2?! It!simply!solves!your!difficult!redundant!problems! …!and!gets!out!of!your!way!

  3. You!are!not!boxed!in…!

  4. …!easy!to!get!started,!yet!powerful!and!flexible!for! advanced!users!

  5. Pre!Zend_ApplicaNon!Bootstrap! Index.php!

  6. Post!Zend_ApplicaNon! Index.php!

  7. “The core architecture is now stable…” – Fabien Potencier hPp://symfony.com/blog/symfony2QfinalQversionQweQareQnotQthereQyet!

  8. In!development!since!December!2009!

  9. A!lot!can!happen! in!a!year! A"baby?"

  10. None
  11. Top"2%"of"projects"on"Ohloh"

  12. 325"Bundles"Published" h>p://symfony2bundles.org/"

  13. What!exactly!is!a!bundle?! A!bundle!is!like!a!plugin! …!except!Symfony2!itself!is!made!up!of!bundles!

  14. “I!was!using!the!same!idea!by!organizing!my!code!in![zend!framework]! modules,!but!this!is!really!painful”! QQ!tawfekov!via!StackOverflow! ! hPp://stackoverflow.com/quesNons/5053369/doQyouQthinkQzendQframeworkQmissesQtheQsymfonysQbundleQprinciple!

  15. Nothing!like!Symfony1!

  16. Less!Magic! config_autoload.yml.php!

  17. Explicit!ConfiguraNon! app/AppKernel.php!

  18. Doctrine2! Doctrine2:!User.php! Doctrine!1.2:!User.php!

  19. Decoupled!design!

  20. None
  21. None
  22. None
  23. None
  24. What makes up Symfony2? ConfiguraNon! Kernel! Directory! Structure! Symfony!Framework!Bundles! Symfony!Components!

  25. Getting started with Symfony2 distributions Similar!to!Linux!distribuNons!

  26. hPp://symfony.com/download!

  27. #!cd!~/Projects/LoneStarPHP! #!tar!xvzf!/path/to/Symfony_Standard_Vendors_2.0.0BETA4.tgz! Extract to your web directory

  28. Check requirements hPp://yourhost/LoneStarPHP/web/config.php! Not!accessing!from!localhost?!! Remove!the!security!check! from:! web/config.php" web/app_dev.php"

  29. Check requirements hPp://yourhost/LoneStarPHP/web/config.php!

  30. Check requirements hPp://yourhost/LoneStarPHP/web/config.php!

  31. Check requirements hPp://yourhost/LoneStarPHP/web/config.php!

  32. Check requirements hPp://yourhost/LoneStarPHP/web/config.php!

  33. Configure the database connection hPp://yourhost/LoneStarPHP/web/app_dev.php/_configurator/step/0! You!can!write!your! own!configuraNon! files!instead!

  34. Yay, Welcome to Symfony! hPp://yourhost/LoneStarPHP/web/app_dev.php!

  35. What!makes!a!page?! /hello/world" A!Route! !/hello/{name}" A!Controller! !A!PHP!funcNon! A!Response! !“<h1>Hello!World!</h1>”!

  36. Step!1:!Create!a!route! /hello/world" File:"app/config/rouKng.yml" ! ! *!RouNng!can!also!be!defined!with!XML,!PHP!and!as!annotaNons! AcmeDemoBundle:LoneStar:hello!! maps!to! !Acme\DemoBundle\Controller\LoneStarController::helloAcNon()!

  37. Step!2:!Create!a!controller! /hello/world" File:"src/Acme/DemoBundle/Controller/LoneStarController.php" ! ! *!At!its!simplest,!a!controller!is!just!a!funcNon!

  38. Step!2:!Create!a!controller! /hello/world" File:"src/Acme/DemoBundle/Controller/LoneStarController.php" ! ! File:"app/config/rouKng.yml" ! !

  39. /hello/world! hPp://yourhost/LoneStarPHP/web/app_dev.php/hello/world!

  40. Great…!! But!HTML!in!controllers?!&@*$%!""

  41. Meet!Twig" hPp://www.twigQproject.org! src/Acme/DemoBundle/Resources/views/LoneStar/hello.html.twig! src/Acme/DemoBundle/Controller/LoneStarController.php!

  42. Hello!World!" hPp://yourhost/LoneStarPHP/web/app_dev.php/hello/world!

  43. Digging!Deeper" hPp://yourhost/LoneStarPHP/web/app_dev.php/hello/world!

  44. Digging!Deeper" hPp://yourhost/LoneStarPHP/web/app_dev.php/hello/world!

  45. Do!less!work! /hello/world" File:"src/Acme/DemoBundle/Controller/LoneStarController.php" ! !

  46. Give"it"a"try…"