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

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.

Stefan Koopmanschap

October 25, 2012
Tweet

More Decks by Stefan Koopmanschap

Other Decks in Programming

Transcript

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

    View full-size slide

  2. @skoop
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. microframeworks
    Thursday, October 25, 12

    View full-size slide

  8. history of frameworks
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  15. a microframework?
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  20. http://microphp.org/
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  26. silex
    Thursday, October 25, 12

    View full-size slide

  27. silex
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  31. basic features
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  36. extend
    Thursday, October 25, 12

    View full-size slide

  37. extend
    • Doctrine
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  43. how to get started
    Thursday, October 25, 12

    View full-size slide

  44. getting started
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  50. composer
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  53. configure server

    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

    Thursday, October 25, 12

    View full-size slide

  54. hello world
    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

    View full-size slide

  55. twig
    "require": {
    "twig/twig": ">=1.8,<2.0-dev"
    }
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  60. make it more dynamic

    Say hello to




    Thursday, October 25, 12

    View full-size slide

  61. make it more dynamic
    $app->post('/sayhello', function (Request $request) use ($app) {
    return $app->redirect('/hello/'.$request->get('name'));
    });
    Thursday, October 25, 12

    View full-size slide

  62. examples
    Thursday, October 25, 12

    View full-size slide

  63. Thursday, October 25, 12

    View full-size slide

  64. why?
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  69. transcoding app
    Thursday, October 25, 12

    View full-size slide

  70. transcoding app
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  74. transcoding app
    • external API
    • calling API of other applications
    • dashboard showing status
    • used: silex, twig, cilex, PDO
    Thursday, October 25, 12

    View full-size slide

  75. why?
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  79. Thursday, October 25, 12

    View full-size slide

  80. Thursday, October 25, 12

    View full-size slide

  81. Bolt
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  93. questions?
    Thursday, October 25, 12

    View full-size slide

  94. some resources
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  98. Thank you!
    Thursday, October 25, 12

    View full-size slide

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

    View full-size slide