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. history of frameworks • libraries • basic MVC • every

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

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

    developer has their own • full stack: cake, symfony, zend framework • full stack: TNG Thursday, October 25, 12
  4. 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
  5. a microframework? • small codebase • basic request/response handling •

    routing • clean and simple Thursday, October 25, 12
  6. silex • set of Symfony2 components • add extensions for

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

    extra functionality • add your own logic Thursday, October 25, 12
  8. extend • Doctrine • Twig • Session • Translation •

    Validation • Caching Thursday, October 25, 12
  9. getting started • set up project • configure server •

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

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

    add front controller • .... • PROFIT Thursday, October 25, 12
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. make it more dynamic $app->post('/sayhello', function (Request $request) use ($app)

    { return $app->redirect('/hello/'.$request->get('name')); }); Thursday, October 25, 12
  18. why? • simple website • get some stuff from the

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

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

    database • display it on screen • used: silex, twig, PDO Thursday, October 25, 12
  21. transcoding app • external API • calling API of other

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

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

    applications • dashboard showing status • used: silex, twig, cilex, PDO Thursday, October 25, 12
  24. why? • full stack makes no sense • lightweight needed

    • maintainers needed simple code Thursday, October 25, 12
  25. Bolt • Simple CMS • Focus on designers/frontenders • Ease

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

    • ... Thursday, October 25, 12