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 Slide

  2. @skoop
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  7. microframeworks
    Thursday, October 25, 12

    View Slide

  8. history of frameworks
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 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 Slide

  15. a microframework?
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  26. silex
    Thursday, October 25, 12

    View Slide

  27. silex
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  31. basic features
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  36. extend
    Thursday, October 25, 12

    View Slide

  37. extend
    • Doctrine
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  44. getting started
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  50. composer
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View 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 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 Slide

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

    View Slide

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

    View Slide

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

    View 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 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 Slide

  60. make it more dynamic

    Say hello to




    Thursday, October 25, 12

    View 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 Slide

  62. examples
    Thursday, October 25, 12

    View Slide

  63. Thursday, October 25, 12

    View Slide

  64. why?
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  69. transcoding app
    Thursday, October 25, 12

    View Slide

  70. transcoding app
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  75. why?
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  79. Thursday, October 25, 12

    View Slide

  80. Thursday, October 25, 12

    View Slide

  81. Bolt
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  93. questions?
    Thursday, October 25, 12

    View Slide

  94. some resources
    Thursday, October 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  98. Thank you!
    Thursday, October 25, 12

    View Slide

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

    View Slide