SlideShare a Scribd company logo
1 of 73
Download to read offline
Hands on with
 Symfony2
   Ryan Weaver
   @weaverryan
Who is this dude?
• Co-author of the Symfony2 Docs

• Core Symfony2 contributor

• Founder of KnpLabs US

• Geek, running, Nashville
http://www.twitter.com/weaverryan
http://www.github.com/weaverryan
iostudio
• Advertising & Integrated Marketing Solutions

• A great, growing Nashville tech company

• Hiring good developers (of all backgrounds)
to be part of a dynamic, fun team

          http://iostudio.com/careers
KnpLabs
Quality. Innovation. Excitement.

• Your symfony/Symfony2 development experts
• Consulting & application auditing
• Symfony2 Training
• Behind lots of open source initiatives
Symfony2 Training
• Right here in Nashville: May 19th & 20th
  • real coding, real project
  • Doctrine2, forms, security, caching, etc
  • Cool libraries like Assetic, Imagine, Behat
  • Lot’s more
• Or join us in New York City: June 6th & 7th

  http://bit.ly/symfony-training
Act 1:

Meet Symfony
What is Symfony2?

      Symfony is a PHP
Framework, a Philosophy, and
  a Community - all working
     together in harmony.


  symfony.com/what-is-symfony
Symfony2
• A group of standalone PHP components

• Bundled into a full-service framework

Solves your difficult, redundant problems

... and then stays the hell out of the way
Problems Solved
• Data persistence   • Asset Management
  (via Doctrine)     • Routing
• Security           • File+Dir Traversing
• Forms              • Translation
• Validation         • Dependency Injection
• Templating         • Image Manipulation
• Autoloading        • Console Tasks
• Logging            • Caching
Act 2:

Why Symfony2?
Symfony2 is fast

 By way of comparison, Symfony 2.0
 is about 3 times faster than Version
  1.4 or than Zend Framework 1.10,
 while taking up 2 times less memory.

http://symfony.com/six-good-technical-reasons
Symfony2 is full-featured
“Symfony2 is an extremely
full featured, modular, and
  crazy fast framework.”
              Steve Francia
              Vice President of Engineering at OpenSky




    spf13.com/post/symfony2
Infinitely Flexible Architecture
“Symfony2 is probably one of the
most flexible PHP frameworks ever
 created. You can literally change
           everything.”

                    ~ Blog.NewITFarmer.com



 http://bit.ly/symfony-new-it-farmer
A huge community of
       developers
• 167 core contributors
• 87 documentation contributors
... and counting ...
A huge eco-system of open
     source libraries
 • 223 open source Symfony2 bundles
 • 74 open source Symfony2 projects
 ... and counting ...
Symfony2Bundles.org


• 223 open source bundles
• 74 open source projects


     http://symfony2bundles.org/
Proven Reputation
• One of the most popular PHP frameworks in
the world

• First released in October 2005
• Nearly 100 releases
• Powers a lot of big sites
nationalguard.com, dailymotion.com, exercise.com, shopopensky.com, etc
Act 3:

Dive into Symfony
The “Standard Distribution”
• Symfony offers “distributions” (think Ubuntu)

• The “Standard Distribution” comes with
everything you’ll need + some bonuses

  • Fully-functional application
  • Intelligent default configuration
  • Some demo pages we can play with
Step 1: Get it!




symfony.com/download
Step 2: Unzip it!


$ cd /path/to/webroot

$ tar zxvf /path/to/Symfony_Standard_Vendors_2.0.0PR11.tgz
Step 3: Run it!




http://localhost/Symfony/web/config.php
Tend to your Garden

•Fix any major problems (e.g. missing libraries,
 permissions issues) that Symfony reports

• Then click “Configure your Symfony
 Application online”
Step 3: Configure it!

 Optional: but a
nice interface to
get you started
     quickly
Finished!


This *is* your
first Symfony2
     page
Act 4:

Let’s create some pages
The 3 Steps to a Page
                /hello/ryan
Step1: Symfony matches the URL to a route

Step2: Symfony executes the controller (a
      PHP function) of the route

Step3: The controller (your code) returns a
       Symfony Response object

          <h1>Hello ryan!</h1>
Hello {insert-name}!


• Our goal: to create a hello world-like app

• ... and then to make it do all sorts of
interesting things ...

remove half the code, JSON version, security,
caching...
Step1: Symfony matches the
          URL to a route
    You define the routes (URLs) of your app

              _welcome:

     /            pattern: /
                  defaults: { _controller: AcmeDemoBundle:Welcome:index }




              hello_demo:
/hello/ryan       pattern: /hello/{name}
                  defaults: { _controller: AcmeDemoBundle:Meetup:hello }
Homework
                 Add the following route to
                  app/config/routing.yml

     hello_demo:
         pattern: /hello/{name}
         defaults: { _controller: AcmeDemoBundle:Meetup:hello }




** Routes can also be defined in XML, PHP and as annotations
Step2: Symfony executes the
       controller of the route
    hello_demo:
        pattern: /hello/{name}
        defaults: { _controller: AcmeDemoBundle:Meetup:hello }



                 Controller Class::method()

AcmeDemoBundleControllerMeetupController::helloAction()


 Symfony will execute this PHP method
Homework
           Create the controller class:
<?php
// src/Acme/DemoBundle/Controller/MeetupController.php
namespace AcmeDemoBundleController;

use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationResponse;

class MeetupController extends Controller
{
    public function helloAction($name)
    {
        return new Response('Hello '.$name);
    }
}
Step 3: The Controller returns
a Symfony Response object
use SymfonyComponentHttpFoundationResponse;

public function helloAction($name)
{
    return new Response('Hello '.$name);
}


  This is the only requirement of a controller
Routing Placeholders
           The route matches URLs like /hello/*
    hello_demo:
        pattern: /hello/{name}
        defaults: { _controller: AcmeDemoBundle:Meetup:hello }


    use SymfonyComponentHttpFoundationResponse;

    public function helloAction($name)
    {
        return new Response('Hello '.$name);
    }


And gives you access to the {name} value
It’s Alive!




http://localhost/Symfony/web/app_dev.php/hello/ryan
Rendering a Template
• A template is a tool that you may choose to use

• A template is used to generate “presentation”
code (e.g. HTML)

• Keep your pretty (<div>) code away from your
nerdy ($foo->sendEmail($body)) code
Homework
      Render a template in the controller

public function helloAction($name)
{
    $response = $this->render(
        'AcmeDemoBundle:Meetup:hello.html.twig',
        array('name' => $name)
    );

    return $response;
}
Homework
                     Create the template file
  {# src/Acme/DemoBundle/Resources/views/Meetup/hello.html.twig #}

  Hello {{ name }}


     This is Twig
Twig is a fast, secure and powerful templating engine

We *LOVE* Twig... but

Symfony2 fully supports Twig and regular
PHP templates
It’s Still Alive!




http://localhost/Symfony/web/app_dev.php/hello/ryan
Dress that Template
• All pages share common elements (header,
footer, sidebar, etc)

• We think about the problem differently: a
template can be decorated by another
template inheritance allows you to build a
base "layout" template that contains all the
common elements of your site and defines
"blocks" that child templates can override
A base layout file                header
 defines “blocks”

Each block can have
  a default value       sidebar            content

{% block header %}
    <h1>Welcome!</h1>
{% endblock %}
The child template “extends”                  header

         the parent


and “overrides” the parent’s        sidebar            content


          blocks


{% block header %}
    <h1>Super hello Welcome!</h1>
{% endblock %}
Homework
      Make the template extend a base template

{# src/Acme/DemoBundle/Resources/views/Meetup/hello.html.twig #}
{% extends "AcmeDemoBundle::layout.html.twig" %}

{% block title "Hello " ~ name %}

{% block content %}
    <h1>Hello {{ name }}!</h1>
{% endblock %}




layout: src/Acme/DemoBundle/Resources/views/layout.html.twig
It’s Beautiful!




http://localhost/Symfony/web/app_dev.php/hello/ryan
Act 5:

Remove all the code
Do Less Work
• So far, we have:
  • a route
  • a controller
  • a template

• We can do all of this with even less code
Homework
                     Change your
                 app/config/routing.yml

hello_demo:
    resource: "@AcmeDemoBundle/Controller/MeetupController.php"
    type:     annotation



This now imports routing information from our controller
Homework
          Add the route to your controller
   /**
     * @extra:Route("/hello/{name}", name="hello_demo")
     */
                                  The PHP comments are
   public function helloAction($name)
   {
        $response = $this->render(
                                   called “annotations”
            'AcmeDemoBundle:Meetup:hello.html.twig',
            array('name' => $name)
Symfony can use annotations to read routing config
        );

       return $response;
Your route and controller are in the same place!
   }
Annotations
 /**
   * @extra:Route("/hello/{name}", name="hello_demo")
   */
 public function helloAction($name)                       The PHP
 {
      $response = $this->render(                        comments are
          'AcmeDemoBundle:Meetup:hello.html.twig',
          array('name' => $name)                            called
      );
                                                        “annotations”
     return $response;
 }




Symfony can use annotations to read routing config
Your route and controller are in the same place!
Remove more code
Instead of rendering the template, tell Symfony
to do it for you
   /**
     * @extra:Route("/hello/{name}", name="hello_demo")
     * @extra:Template()
     */
   public function helloAction($name)
   {
        return array('name' => $name);
   }
/**
      * @extra:Route("/hello/{name}", name="hello_demo")
      * @extra:Template()
      */
    public function helloAction($name)
    {
         return array('name' => $name);
    }



   Controller: AcmeDemoBundle:Meetup:hello


Template: AcmeDemoBundle:Meetup:hello.html.twig
Now with less code!




http://localhost/Symfony/web/app_dev.php/hello/ryan
Act 6:

JSON { name: “Ryan” }
Create a JSON API
• We have an HTML version of our page

• How about a JSON version?
Add a _format to the route
/**
  * @extra:Route("/hello/{name}.{_format}", defaults={"_format"="html"})
  * @extra:Template()
  */
public function helloAction($name)
{
     return array('name' => $name);
}




“/hello/ryan” still works exactly as before
Create a JSON template
{# src/Acme/DemoBundle/Resources/views/Meetup/hello.json.twig #}

{% set arr = { 'name': name } %}

{{ arr | json_encode | raw }}




          “/hello/ryan.json” renders a JSON array

                        {"name":"ryan"}

                        It’s that simple
To review
• Symfony looks for the value of the special
“_format” routing placeholder

• The _format is used in the name of the
template (hello.json.twig)

• Symfony also returns the proper Content-
Type (application/json)
RestBundle
  • For a truly robust solution to RESTful API’s,
  see the community-driven RestBundle




https://github.com/FriendsOfSymfony/RestBundle
Act 7:

With annotations, you can
Add security
/**
  * @extra:Route("/hello/admin/{name}")
  * @extra:Secure(roles="ROLE_ADMIN")
  * @extra:Template()
  */
public function helloadminAction($name)
{
     return array('name' => $name);
}
Add caching

/**
  * @extra:Route("/hello/{name}.{_format}", defaults={"_format"="html"})
  * @extra:Template()
  * @extra:Cache(maxage="86400")
  */
public function helloAction($name)
{
     return array('name' => $name);
}
Act 8:

PHP Libraries by the
Symfony Community
Doctrine2
        http://www.doctrine-project.org/

• Database Abstraction Library (DBAL)

• Object Relational Mapper (ORM)

• Object Document Mapper (ODM)
   --> (for Mongo DB)

Doctrine persists data better than anyone
Assetic
     https://github.com/kriswallsmith/assetic
• PHP asset management framework

• Run CSS and JS through filters
  • LESS, SASS and others
  • Compress the assets

• Compile CSS and JS into a single file each
Behat + Mink
                http://behat.org/

• Behavioral-driven development framework




• Write human-readable sentences that test
your code (and can be run in a browser)
Gaufrette
      https://github.com/knplabs/Gaufrette
• PHP filesystem abstraction library
     // ... setup your filesystem

     $content = $filesystem->read('myFile');
     $content = 'Hello I am the new content';

     $filesystem->write('myFile', $content);



• Read and write from Amazon S3 or FTP like a
local filesystem
Imagine
    https://github.com/avalanche123/Imagine
• PHP Image manipulation library
     use ImagineImageBox;
     use ImagineImagePoint;

     $image->resize(new Box(15, 25))
         ->rotate(45)
         ->crop(new Point(0, 0), new Box(45, 45))
         ->save('/path/to/new/image.jpg');


• Does crazy things and has crazy docs
Silex
                http://silex-project.org/
• Microframework built from Symfony2 Components
      require_once __DIR__.'/silex.phar';

      $app = new SilexApplication();

      $app->get('/hello/{name}', function($name) {
          return "Hello $name";
      });

      $app->run();


• That’s your whole app :)
Sonata Admin Bundle
  https://github.com/sonata-project/AdminBundle
• Admin generator for Symfony2
Act 9:

Last words
Symfony2 is...

• Fast as hell
• Infinitely flexible
• Fully-featured
• Driven by a huge community

• Not released yet...
    Release candidate coming very soon...
Thanks!
                      Questions?
                   Ryan Weaver
                   @weaverryan



  Symfony2 Training
    in Nashville

Join us May 19th & 20th

More Related Content

What's hot

Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestJoshua Warren
 
Learning puppet chapter 2
Learning puppet chapter 2Learning puppet chapter 2
Learning puppet chapter 2Vishal Biyani
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Matthew McCullough
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoRyan Weaver
 
Composer
ComposerComposer
Composercmodijk
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7Damien Seguy
 
Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingDougal Campbell
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017Ryan Weaver
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Componentsguest0de7c2
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupalsparkfabrik
 
Getting big without getting fat, in perl
Getting big without getting fat, in perlGetting big without getting fat, in perl
Getting big without getting fat, in perlDean Hamstead
 

What's hot (20)

Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Learning puppet chapter 2
Learning puppet chapter 2Learning puppet chapter 2
Learning puppet chapter 2
 
Maven 3.0 at Øredev
Maven 3.0 at ØredevMaven 3.0 at Øredev
Maven 3.0 at Øredev
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
Creating custom themes in AtoM
Creating custom themes in AtoMCreating custom themes in AtoM
Creating custom themes in AtoM
 
Composer
ComposerComposer
Composer
 
Phpbasics
PhpbasicsPhpbasics
Phpbasics
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
Php simple
Php simplePhp simple
Php simple
 
Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin Programming
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & DrupalBehaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
 
Getting big without getting fat, in perl
Getting big without getting fat, in perlGetting big without getting fat, in perl
Getting big without getting fat, in perl
 

Similar to Hands-on with the Symfony2 Framework

Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi
 
Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fwdays
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Fabien Potencier
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Fabien Potencier
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)Fabien Potencier
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Antonio Peric-Mazar
 
Symfony 4: A new way to develop applications #phpsrb
 Symfony 4: A new way to develop applications #phpsrb Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #phpsrbAntonio Peric-Mazar
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Fabrice Bernhard
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvarsSam Marley-Jarrett
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsDeepak Chandani
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Ondřej Machulda
 
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii BodarevEcto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii BodarevElixir Club
 
Ecto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With ElixirEcto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With ElixirYurii Bodarev
 

Similar to Hands-on with the Symfony2 Framework (20)

Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8
 
Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19
 
Symfony 4: A new way to develop applications #phpsrb
 Symfony 4: A new way to develop applications #phpsrb Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #phpsrb
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
1.symfony 4 intro
1.symfony 4 intro1.symfony 4 intro
1.symfony 4 intro
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii BodarevEcto and Phoenix: Doing web with Elixir - Yurii Bodarev
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
 
Ecto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With ElixirEcto and Phoenix: Doing Web With Elixir
Ecto and Phoenix: Doing Web With Elixir
 

More from Ryan Weaver

Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Ryan Weaver
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityRyan Weaver
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatRyan Weaver
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexRyan Weaver
 
Silex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonySilex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonyRyan Weaver
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itRyan Weaver
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsRyan Weaver
 
The Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsThe Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsRyan Weaver
 
A PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appA PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appRyan Weaver
 
Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Ryan Weaver
 
Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with TwigRyan Weaver
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 MinutesRyan Weaver
 
Dependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear youDependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear youRyan Weaver
 
The Art of Doctrine Migrations
The Art of Doctrine MigrationsThe Art of Doctrine Migrations
The Art of Doctrine MigrationsRyan Weaver
 

More from Ryan Weaver (16)

Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
Silex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonySilex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender Symfony
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 
The Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsThe Wonderful World of Symfony Components
The Wonderful World of Symfony Components
 
A PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appA PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 app
 
Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)
 
Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with Twig
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 Minutes
 
Dependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear youDependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear you
 
The Art of Doctrine Migrations
The Art of Doctrine MigrationsThe Art of Doctrine Migrations
The Art of Doctrine Migrations
 

Recently uploaded

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Hands-on with the Symfony2 Framework

  • 1. Hands on with Symfony2 Ryan Weaver @weaverryan
  • 2. Who is this dude? • Co-author of the Symfony2 Docs • Core Symfony2 contributor • Founder of KnpLabs US • Geek, running, Nashville http://www.twitter.com/weaverryan http://www.github.com/weaverryan
  • 3. iostudio • Advertising & Integrated Marketing Solutions • A great, growing Nashville tech company • Hiring good developers (of all backgrounds) to be part of a dynamic, fun team http://iostudio.com/careers
  • 4. KnpLabs Quality. Innovation. Excitement. • Your symfony/Symfony2 development experts • Consulting & application auditing • Symfony2 Training • Behind lots of open source initiatives
  • 5. Symfony2 Training • Right here in Nashville: May 19th & 20th • real coding, real project • Doctrine2, forms, security, caching, etc • Cool libraries like Assetic, Imagine, Behat • Lot’s more • Or join us in New York City: June 6th & 7th http://bit.ly/symfony-training
  • 7. What is Symfony2? Symfony is a PHP Framework, a Philosophy, and a Community - all working together in harmony. symfony.com/what-is-symfony
  • 8. Symfony2 • A group of standalone PHP components • Bundled into a full-service framework Solves your difficult, redundant problems ... and then stays the hell out of the way
  • 9. Problems Solved • Data persistence • Asset Management (via Doctrine) • Routing • Security • File+Dir Traversing • Forms • Translation • Validation • Dependency Injection • Templating • Image Manipulation • Autoloading • Console Tasks • Logging • Caching
  • 11. Symfony2 is fast By way of comparison, Symfony 2.0 is about 3 times faster than Version 1.4 or than Zend Framework 1.10, while taking up 2 times less memory. http://symfony.com/six-good-technical-reasons
  • 12. Symfony2 is full-featured “Symfony2 is an extremely full featured, modular, and crazy fast framework.” Steve Francia Vice President of Engineering at OpenSky spf13.com/post/symfony2
  • 13. Infinitely Flexible Architecture “Symfony2 is probably one of the most flexible PHP frameworks ever created. You can literally change everything.” ~ Blog.NewITFarmer.com http://bit.ly/symfony-new-it-farmer
  • 14. A huge community of developers • 167 core contributors • 87 documentation contributors ... and counting ...
  • 15. A huge eco-system of open source libraries • 223 open source Symfony2 bundles • 74 open source Symfony2 projects ... and counting ...
  • 16. Symfony2Bundles.org • 223 open source bundles • 74 open source projects http://symfony2bundles.org/
  • 17. Proven Reputation • One of the most popular PHP frameworks in the world • First released in October 2005 • Nearly 100 releases • Powers a lot of big sites nationalguard.com, dailymotion.com, exercise.com, shopopensky.com, etc
  • 18. Act 3: Dive into Symfony
  • 19. The “Standard Distribution” • Symfony offers “distributions” (think Ubuntu) • The “Standard Distribution” comes with everything you’ll need + some bonuses • Fully-functional application • Intelligent default configuration • Some demo pages we can play with
  • 20. Step 1: Get it! symfony.com/download
  • 21. Step 2: Unzip it! $ cd /path/to/webroot $ tar zxvf /path/to/Symfony_Standard_Vendors_2.0.0PR11.tgz
  • 22. Step 3: Run it! http://localhost/Symfony/web/config.php
  • 23. Tend to your Garden •Fix any major problems (e.g. missing libraries, permissions issues) that Symfony reports • Then click “Configure your Symfony Application online”
  • 24. Step 3: Configure it! Optional: but a nice interface to get you started quickly
  • 26. Act 4: Let’s create some pages
  • 27. The 3 Steps to a Page /hello/ryan Step1: Symfony matches the URL to a route Step2: Symfony executes the controller (a PHP function) of the route Step3: The controller (your code) returns a Symfony Response object <h1>Hello ryan!</h1>
  • 28. Hello {insert-name}! • Our goal: to create a hello world-like app • ... and then to make it do all sorts of interesting things ... remove half the code, JSON version, security, caching...
  • 29. Step1: Symfony matches the URL to a route You define the routes (URLs) of your app _welcome: / pattern: / defaults: { _controller: AcmeDemoBundle:Welcome:index } hello_demo: /hello/ryan pattern: /hello/{name} defaults: { _controller: AcmeDemoBundle:Meetup:hello }
  • 30. Homework Add the following route to app/config/routing.yml hello_demo: pattern: /hello/{name} defaults: { _controller: AcmeDemoBundle:Meetup:hello } ** Routes can also be defined in XML, PHP and as annotations
  • 31. Step2: Symfony executes the controller of the route hello_demo: pattern: /hello/{name} defaults: { _controller: AcmeDemoBundle:Meetup:hello } Controller Class::method() AcmeDemoBundleControllerMeetupController::helloAction() Symfony will execute this PHP method
  • 32. Homework Create the controller class: <?php // src/Acme/DemoBundle/Controller/MeetupController.php namespace AcmeDemoBundleController; use SymfonyBundleFrameworkBundleControllerController; use SymfonyComponentHttpFoundationResponse; class MeetupController extends Controller { public function helloAction($name) { return new Response('Hello '.$name); } }
  • 33. Step 3: The Controller returns a Symfony Response object use SymfonyComponentHttpFoundationResponse; public function helloAction($name) { return new Response('Hello '.$name); } This is the only requirement of a controller
  • 34. Routing Placeholders The route matches URLs like /hello/* hello_demo: pattern: /hello/{name} defaults: { _controller: AcmeDemoBundle:Meetup:hello } use SymfonyComponentHttpFoundationResponse; public function helloAction($name) { return new Response('Hello '.$name); } And gives you access to the {name} value
  • 36. Rendering a Template • A template is a tool that you may choose to use • A template is used to generate “presentation” code (e.g. HTML) • Keep your pretty (<div>) code away from your nerdy ($foo->sendEmail($body)) code
  • 37. Homework Render a template in the controller public function helloAction($name) { $response = $this->render( 'AcmeDemoBundle:Meetup:hello.html.twig', array('name' => $name) ); return $response; }
  • 38. Homework Create the template file {# src/Acme/DemoBundle/Resources/views/Meetup/hello.html.twig #} Hello {{ name }} This is Twig Twig is a fast, secure and powerful templating engine We *LOVE* Twig... but Symfony2 fully supports Twig and regular PHP templates
  • 40. Dress that Template • All pages share common elements (header, footer, sidebar, etc) • We think about the problem differently: a template can be decorated by another
  • 41. template inheritance allows you to build a base "layout" template that contains all the common elements of your site and defines "blocks" that child templates can override
  • 42. A base layout file header defines “blocks” Each block can have a default value sidebar content {% block header %} <h1>Welcome!</h1> {% endblock %}
  • 43. The child template “extends” header the parent and “overrides” the parent’s sidebar content blocks {% block header %} <h1>Super hello Welcome!</h1> {% endblock %}
  • 44. Homework Make the template extend a base template {# src/Acme/DemoBundle/Resources/views/Meetup/hello.html.twig #} {% extends "AcmeDemoBundle::layout.html.twig" %} {% block title "Hello " ~ name %} {% block content %} <h1>Hello {{ name }}!</h1> {% endblock %} layout: src/Acme/DemoBundle/Resources/views/layout.html.twig
  • 46. Act 5: Remove all the code
  • 47. Do Less Work • So far, we have: • a route • a controller • a template • We can do all of this with even less code
  • 48. Homework Change your app/config/routing.yml hello_demo: resource: "@AcmeDemoBundle/Controller/MeetupController.php" type: annotation This now imports routing information from our controller
  • 49. Homework Add the route to your controller /** * @extra:Route("/hello/{name}", name="hello_demo") */ The PHP comments are public function helloAction($name) { $response = $this->render( called “annotations” 'AcmeDemoBundle:Meetup:hello.html.twig', array('name' => $name) Symfony can use annotations to read routing config ); return $response; Your route and controller are in the same place! }
  • 50. Annotations /** * @extra:Route("/hello/{name}", name="hello_demo") */ public function helloAction($name) The PHP { $response = $this->render( comments are 'AcmeDemoBundle:Meetup:hello.html.twig', array('name' => $name) called ); “annotations” return $response; } Symfony can use annotations to read routing config Your route and controller are in the same place!
  • 51. Remove more code Instead of rendering the template, tell Symfony to do it for you /** * @extra:Route("/hello/{name}", name="hello_demo") * @extra:Template() */ public function helloAction($name) { return array('name' => $name); }
  • 52. /** * @extra:Route("/hello/{name}", name="hello_demo") * @extra:Template() */ public function helloAction($name) { return array('name' => $name); } Controller: AcmeDemoBundle:Meetup:hello Template: AcmeDemoBundle:Meetup:hello.html.twig
  • 53. Now with less code! http://localhost/Symfony/web/app_dev.php/hello/ryan
  • 54. Act 6: JSON { name: “Ryan” }
  • 55. Create a JSON API • We have an HTML version of our page • How about a JSON version?
  • 56. Add a _format to the route /** * @extra:Route("/hello/{name}.{_format}", defaults={"_format"="html"}) * @extra:Template() */ public function helloAction($name) { return array('name' => $name); } “/hello/ryan” still works exactly as before
  • 57. Create a JSON template {# src/Acme/DemoBundle/Resources/views/Meetup/hello.json.twig #} {% set arr = { 'name': name } %} {{ arr | json_encode | raw }} “/hello/ryan.json” renders a JSON array {"name":"ryan"} It’s that simple
  • 58. To review • Symfony looks for the value of the special “_format” routing placeholder • The _format is used in the name of the template (hello.json.twig) • Symfony also returns the proper Content- Type (application/json)
  • 59. RestBundle • For a truly robust solution to RESTful API’s, see the community-driven RestBundle https://github.com/FriendsOfSymfony/RestBundle
  • 61. Add security /** * @extra:Route("/hello/admin/{name}") * @extra:Secure(roles="ROLE_ADMIN") * @extra:Template() */ public function helloadminAction($name) { return array('name' => $name); }
  • 62. Add caching /** * @extra:Route("/hello/{name}.{_format}", defaults={"_format"="html"}) * @extra:Template() * @extra:Cache(maxage="86400") */ public function helloAction($name) { return array('name' => $name); }
  • 63. Act 8: PHP Libraries by the Symfony Community
  • 64. Doctrine2 http://www.doctrine-project.org/ • Database Abstraction Library (DBAL) • Object Relational Mapper (ORM) • Object Document Mapper (ODM) --> (for Mongo DB) Doctrine persists data better than anyone
  • 65. Assetic https://github.com/kriswallsmith/assetic • PHP asset management framework • Run CSS and JS through filters • LESS, SASS and others • Compress the assets • Compile CSS and JS into a single file each
  • 66. Behat + Mink http://behat.org/ • Behavioral-driven development framework • Write human-readable sentences that test your code (and can be run in a browser)
  • 67. Gaufrette https://github.com/knplabs/Gaufrette • PHP filesystem abstraction library // ... setup your filesystem $content = $filesystem->read('myFile'); $content = 'Hello I am the new content'; $filesystem->write('myFile', $content); • Read and write from Amazon S3 or FTP like a local filesystem
  • 68. Imagine https://github.com/avalanche123/Imagine • PHP Image manipulation library use ImagineImageBox; use ImagineImagePoint; $image->resize(new Box(15, 25)) ->rotate(45) ->crop(new Point(0, 0), new Box(45, 45)) ->save('/path/to/new/image.jpg'); • Does crazy things and has crazy docs
  • 69. Silex http://silex-project.org/ • Microframework built from Symfony2 Components require_once __DIR__.'/silex.phar'; $app = new SilexApplication(); $app->get('/hello/{name}', function($name) { return "Hello $name"; }); $app->run(); • That’s your whole app :)
  • 70. Sonata Admin Bundle https://github.com/sonata-project/AdminBundle • Admin generator for Symfony2
  • 72. Symfony2 is... • Fast as hell • Infinitely flexible • Fully-featured • Driven by a huge community • Not released yet... Release candidate coming very soon...
  • 73. Thanks! Questions? Ryan Weaver @weaverryan Symfony2 Training in Nashville Join us May 19th & 20th