Silex: Creating websites in hours instead of days

Silex: Creating websites in hours instead of days

With the introduction of the latest generation of PHP frameworks another "wave" started as well: microframeworks. More lean, small and flexible, these microframeworks pose an interesting alternative to full-stack frameworks. What is a microframework exactly? How to use it? During this talk you will learn about this by example using the Silex microframework.

A8f72e32766355f12a56ede9aaa0ee78?s=128

Stefan Koopmanschap

October 25, 2012
Tweet

Transcript

  1. Silex Creating websites in hours instead of days Thursday, October

    25, 12
  2. @skoop Thursday, October 25, 12

  3. @skoop • PHP * Thursday, October 25, 12

  4. @skoop • PHP * • Ingewikkeld Thursday, October 25, 12

  5. @skoop • PHP * • Ingewikkeld • PFZ.nl / PFCongres.com

    Thursday, October 25, 12
  6. @skoop • PHP * • Ingewikkeld • PFZ.nl / PFCongres.com

    • Symfony Thursday, October 25, 12
  7. microframeworks Thursday, October 25, 12

  8. history of frameworks Thursday, October 25, 12

  9. history of frameworks • libraries Thursday, October 25, 12

  10. history of frameworks • libraries • basic MVC Thursday, October

    25, 12
  11. history of frameworks • libraries • basic MVC • every

    developer has their own Thursday, October 25, 12
  12. history of frameworks • libraries • basic MVC • every

    developer has their own • full stack: cake, symfony, zend framework Thursday, October 25, 12
  13. history of frameworks • libraries • basic MVC • every

    developer has their own • full stack: cake, symfony, zend framework • full stack: TNG Thursday, October 25, 12
  14. history of frameworks • libraries • basic MVC • every

    developer has their own • full stack: cake, symfony, zend framework • full stack: TNG • microframeworks Thursday, October 25, 12
  15. a microframework? Thursday, October 25, 12

  16. a microframework? • small codebase Thursday, October 25, 12

  17. a microframework? • small codebase • basic request/response handling Thursday,

    October 25, 12
  18. a microframework? • small codebase • basic request/response handling •

    routing Thursday, October 25, 12
  19. a microframework? • small codebase • basic request/response handling •

    routing • clean and simple Thursday, October 25, 12
  20. http://microphp.org/ Thursday, October 25, 12

  21. why use microframeworks? Thursday, October 25, 12

  22. why use microframeworks? • prototyping Thursday, October 25, 12

  23. why use microframeworks? • prototyping • API’s Thursday, October 25,

    12
  24. why use microframeworks? • prototyping • API’s • simple websites

    Thursday, October 25, 12
  25. why use microframeworks? • prototyping • API’s • simple websites

    • performance Thursday, October 25, 12
  26. silex Thursday, October 25, 12

  27. silex Thursday, October 25, 12

  28. silex • set of Symfony2 components Thursday, October 25, 12

  29. silex • set of Symfony2 components • add extensions for

    extra functionality Thursday, October 25, 12
  30. silex • set of Symfony2 components • add extensions for

    extra functionality • add your own logic Thursday, October 25, 12
  31. basic features Thursday, October 25, 12

  32. basic features • request/response handling Thursday, October 25, 12

  33. basic features • request/response handling • routing Thursday, October 25,

    12
  34. basic features • request/response handling • routing • dependency injection

    Thursday, October 25, 12
  35. basic features • request/response handling • routing • dependency injection

    • extensibility Thursday, October 25, 12
  36. extend Thursday, October 25, 12

  37. extend • Doctrine Thursday, October 25, 12

  38. extend • Doctrine • Twig Thursday, October 25, 12

  39. extend • Doctrine • Twig • Session Thursday, October 25,

    12
  40. extend • Doctrine • Twig • Session • Translation Thursday,

    October 25, 12
  41. extend • Doctrine • Twig • Session • Translation •

    Validation Thursday, October 25, 12
  42. extend • Doctrine • Twig • Session • Translation •

    Validation • Caching Thursday, October 25, 12
  43. how to get started Thursday, October 25, 12

  44. getting started Thursday, October 25, 12

  45. getting started • set up project Thursday, October 25, 12

  46. getting started • set up project • configure server Thursday,

    October 25, 12
  47. getting started • set up project • configure server •

    add front controller Thursday, October 25, 12
  48. getting started • set up project • configure server •

    add front controller • .... Thursday, October 25, 12
  49. getting started • set up project • configure server •

    add front controller • .... • PROFIT Thursday, October 25, 12
  50. composer Thursday, October 25, 12

  51. composer composer create-project silex/silex project Thursday, October 25, 12

  52. composer composer create-project silex/silex project composer create-project fabpot/silex-skeleton project Thursday,

    October 25, 12
  53. configure server <VirtualHost *:80> DocumentRoot "/Users/stefan/php/silex-talk/project/public" ServerName silex-talk FallbackResource /index.php

    ErrorLog "logs/silextalk.error_log" CustomLog "logs/silextalk.access_log" common </VirtualHost> Thursday, October 25, 12
  54. hello world <?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->get('/hello/{name}',

    function ($name) use ($app) { return 'Hello '.$app->escape($name); }); $app->run(); Thursday, October 25, 12
  55. twig "require": { "twig/twig": ">=1.8,<2.0-dev" } Thursday, October 25, 12

  56. twig "require": { "twig/twig": ">=1.8,<2.0-dev" } composer update Thursday, October

    25, 12
  57. twig $app = new Silex\Application(); $app->register( new Silex\Provider\TwigServiceProvider(), array( 'twig.path'

    => __DIR__.'/../views', ) ); Thursday, October 25, 12
  58. twig $app = new Silex\Application(); $app->register( new Silex\Provider\TwigServiceProvider(), array( 'twig.path'

    => __DIR__.'/../views', ) ); $app->get('/hello/{name}', function ($name) use ($app) { return $app['twig']->render('hello.twig', array( 'name' => $name, )); }); Thursday, October 25, 12
  59. twig $app = new Silex\Application(); $app->register( new Silex\Provider\TwigServiceProvider(), array( 'twig.path'

    => __DIR__.'/../views', ) ); $app->get('/hello/{name}', function ($name) use ($app) { return $app['twig']->render('hello.twig', array( 'name' => $name, )); }); Hello {{ name }} Thursday, October 25, 12
  60. make it more dynamic <form method="post" action="/sayhello"> Say hello to

    <input type="text" name="name" value="{{ name }}" /> <br /> <input type="submit" name="submit" value="Say Hello" /> </form> Thursday, October 25, 12
  61. make it more dynamic $app->post('/sayhello', function (Request $request) use ($app)

    { return $app->redirect('/hello/'.$request->get('name')); }); Thursday, October 25, 12
  62. examples Thursday, October 25, 12

  63. Thursday, October 25, 12

  64. why? Thursday, October 25, 12

  65. why? • simple website Thursday, October 25, 12

  66. why? • simple website • get some stuff from the

    database Thursday, October 25, 12
  67. why? • simple website • get some stuff from the

    database • display it on screen Thursday, October 25, 12
  68. why? • simple website • get some stuff from the

    database • display it on screen • used: silex, twig, PDO Thursday, October 25, 12
  69. transcoding app Thursday, October 25, 12

  70. transcoding app Thursday, October 25, 12

  71. transcoding app • external API Thursday, October 25, 12

  72. transcoding app • external API • calling API of other

    applications Thursday, October 25, 12
  73. transcoding app • external API • calling API of other

    applications • dashboard showing status Thursday, October 25, 12
  74. transcoding app • external API • calling API of other

    applications • dashboard showing status • used: silex, twig, cilex, PDO Thursday, October 25, 12
  75. why? Thursday, October 25, 12

  76. why? • full stack makes no sense Thursday, October 25,

    12
  77. why? • full stack makes no sense • lightweight needed

    Thursday, October 25, 12
  78. why? • full stack makes no sense • lightweight needed

    • maintainers needed simple code Thursday, October 25, 12
  79. Thursday, October 25, 12

  80. Thursday, October 25, 12

  81. Bolt Thursday, October 25, 12

  82. Bolt • Simple CMS Thursday, October 25, 12

  83. Bolt • Simple CMS • Focus on designers/frontenders Thursday, October

    25, 12
  84. Bolt • Simple CMS • Focus on designers/frontenders • Ease

    of use Thursday, October 25, 12
  85. Bolt • Simple CMS • Focus on designers/frontenders • Ease

    of use • uses: silex, twig, sessions, doctrine, caching, forms, validation, translation, etc Thursday, October 25, 12
  86. find the right one Thursday, October 25, 12

  87. find the right one Thursday, October 25, 12

  88. find the right one • Phlyty Thursday, October 25, 12

  89. find the right one • Phlyty • Slim Thursday, October

    25, 12
  90. find the right one • Phlyty • Slim • Limonade

    Thursday, October 25, 12
  91. find the right one • Phlyty • Slim • Limonade

    • ... Thursday, October 25, 12
  92. build your own! Thursday, October 25, 12

  93. questions? Thursday, October 25, 12

  94. some resources Thursday, October 25, 12

  95. some resources • http://silex.sensiolabs.org/ Thursday, October 25, 12

  96. some resources • http://silex.sensiolabs.org/ • https://github.com/fabpot/Silex-Skeleton Thursday, October 25, 12

  97. some resources • http://silex.sensiolabs.org/ • https://github.com/fabpot/Silex-Skeleton • http://bolt.cm/ Thursday, October

    25, 12
  98. Thank you! Thursday, October 25, 12

  99. http://leftontheweb.com/ http://ingewikkeld.net/ https://joind.in/7047 @skoop Thank you! Thursday, October 25, 12