SlideShare a Scribd company logo
Migrare da
 symfony 1
a Symfony2
Massimiliano Arione
     @garakkio

  Torino, 5 ottobre 2012
symfony 1 end of life: nov. 2012
cosa non è Symfony 2
cosa non è Symfony 2
cosa è Symfony2
Dependency Injection Container
come funziona il DIC
<?php
$mailer = $this->get('mailer');
come funziona il DIC
<?php
$mailer = $this->get('mailer');




    niente più sfContext!
come funziona il DIC
<?php
$mailer = $this->get('newsletter');


<?php
namespace AcmeMyBundle;

class Newsletter
{
   protected $mailer;

    public function __construct(Swift_Mailer $mailer)
    {
      $this->mailer = $mailer;
    }
}
come funziona il DIC
<?php
namespace AcmeMyBundle;

use DoctrineORMEntityManager;

class Newsletter
{
   protected $mailer, $em;

    public function __construct(Swift_Mailer $mailer, EntityManager $em)
    {
      $this->mailer = $mailer;
      $this->em = $em;
    }
}
test
model
model
$ app/console doctrine:mapping:import AcmeMyBundle annotation




$ app/console doctrine:generate:entities AcmeMyBundle --no-backup
model
<?php

namespace AcmeMyBundleEntity;
use DoctrineORMMapping as ORM;

/**
 * @ORMTable(name="category")
 * @ORMEntity
 */
class Category
{
    /**
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORMColumn(name="name", type="string", length=255)
     */
    private $name;
}
alcuni bundle da aggiungere

stof/doctrine-extensions-bundle


friendsofsymfony/user-bundle


sonata-project/doctrine-orm-admin-bundle
alcuni bundle da aggiungere

stof/doctrine-extensions-bundle
                              (sf1: behaviours)

friendsofsymfony/user-bundle
                         (sf1: sfGuardPlugin)

sonata-project/doctrine-orm-admin-bundle
                         (sf1: admin generator)
controller
<?php
  /**
   * Lists all Category entities.
   *
   * @Route("/", name="category")
   * @Template()
   */
  public function indexAction()
  {
      $em = $this->getDoctrine()->getManager();
      $entities = $em->getRepository('AcmeMyBundle:Category')->findAll();

      return array(
         'entities' => $entities,
      );
  }
controller
/**
 * @Route("/{id}/show", name="category_show")
 * @Template()
 */
public function showAction($id)
{
    $em = $this->getDoctrine()->getManager();
    $entity = $em->getRepository('AcmeMyBundle:Category')->find($id);
    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Category entity.');
    }
    $deleteForm = $this->createDeleteForm($id);

    return array(
       'entity'   => $entity,
       'delete_form' => $deleteForm->createView(),
    );
}
/**
   * @Route("/create", name="category_create")
   * @Method("POST")
                          controller
   * @Template("AcmeMyBundle:Category:new.html.twig")
   */
  public function createAction(Request $request)
  {
      $entity = new Category();
      $form = $this->createForm(new CategoryType(), $entity);
      $form->bind($request);
      if ($form->isValid()) {
          $em = $this->getDoctrine()->getManager();
          $em->persist($entity);
          $em->flush();

        return $this->redirect($this->generateUrl('category_show', array('id' =>
$entity->getId())));
     }

      return array(
         'entity' => $entity,
         'form' => $form->createView(),
      );
  }
view
{% extends 'AcmeMyBundle::layout.html.twig' %}

{% block content %}

   <h1>Category list</h1>
   <table class="table table-striped table-hover table-bordered records_list">
      <tbody>
      {% for entity in paginator %}
         <tr>
            <td><a href="{{ path('category_show', { 'id': entity.id }) }}">{{ entity.id
}}</a></td>
            <td>{{ entity.name }}</td>
            <td class="btn-group">
               {# ... #}
            </td>
         </tr>
      {% endfor %}
      </tbody>
   </table>

{% endblock %}
cache



http
domande?
grazie!
links
http://twitter.com/garakkio
http://www.slideshare.net/garak

credits
http://text2pic.com/
http://symfony.com/trademark
http://php.net/download-logos.php
http://doophp.com/temp/guide/mvcabout.png
http://grigio.org/html5-linux-day/stuff/client-server.png
https://elearning.industriallogic.com/gh/albums/wrappersAndWalkers/injector/images/big-tomatoes.gif
http://openclipart.org/image/800px/svg_to_png/94723/db.png
http://clivemind.com/wp-content/uploads/2012/07/logo.png
http://www.kidsvoting.dreamhosters.com/uploads/images/vote_1.jpg
http://markup.su/highlighter/

More Related Content

PPTX
Building Your First Widget
TXT
Exemple de création de base
PDF
How kris-writes-symfony-apps-london
PPTX
PDF
Et si on en finissait avec CRUD ?
PDF
Barcelona.pm Curs1211 sess01
PDF
PythonでJWT生成からボット作成、投稿までやってみた
PDF
Dollar symbol
Building Your First Widget
Exemple de création de base
How kris-writes-symfony-apps-london
Et si on en finissait avec CRUD ?
Barcelona.pm Curs1211 sess01
PythonでJWT生成からボット作成、投稿までやってみた
Dollar symbol

What's hot (20)

PDF
Love and Loss: A Symfony Security Play
DOCX
PPTX
6. hello popescu 2
PPTX
London XQuery Meetup: Querying the World (Web Scraping)
PDF
Traavle finalpresentation
PPTX
ZIP
TerminalでTwitter
PDF
Add loop shortcode
ZIP
全裸でワンライナー(仮)
PDF
BDD revolution - or how we came back from hell
KEY
jQuery Namespace Pattern
PPTX
Ch6(mysql front)
PDF
Five things for you - Yahoo developer offers
KEY
Jquery Fundamentals
RTF
PDF
An Introduction to Jquery
PDF
Erik mogensen stowe
PDF
var, let in SIL
PDF
PDF
Kasdorf, EPUB 3: Not Your Father’s EPUB
Love and Loss: A Symfony Security Play
6. hello popescu 2
London XQuery Meetup: Querying the World (Web Scraping)
Traavle finalpresentation
TerminalでTwitter
Add loop shortcode
全裸でワンライナー(仮)
BDD revolution - or how we came back from hell
jQuery Namespace Pattern
Ch6(mysql front)
Five things for you - Yahoo developer offers
Jquery Fundamentals
An Introduction to Jquery
Erik mogensen stowe
var, let in SIL
Kasdorf, EPUB 3: Not Your Father’s EPUB
Ad

Viewers also liked (7)

PDF
Gestione delle dipendenze con Composer
PPT
Lessons learned in PHP
PPT
symfony & jQuery (PUG)
PDF
Case study OmniAuto.it
ODP
Sviluppo rapido di applicazioni con PHP
PPT
Paypal + symfony
PDF
PHP, non lo stesso vecchio linguaggio
Gestione delle dipendenze con Composer
Lessons learned in PHP
symfony & jQuery (PUG)
Case study OmniAuto.it
Sviluppo rapido di applicazioni con PHP
Paypal + symfony
PHP, non lo stesso vecchio linguaggio
Ad

Similar to Migrare da symfony 1 a Symfony2 (20)

KEY
Symfony2 Building on Alpha / Beta technology
PDF
Be RESTful (Symfony Camp 2008)
PDF
How Kris Writes Symfony Apps
PDF
Doctrine For Beginners
PDF
Unittests für Dummies
PDF
Separation of concerns - DPC12
PDF
How I started to love design patterns
PDF
Symfony tips and tricks
PPT
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
KEY
Lithium Best
PDF
Apostrophe
PDF
Unit testing after Zend Framework 1.8
PPTX
Magento Live Australia 2016: Request Flow
ODP
Rich domain model with symfony 2.5 and doctrine 2.5
PPTX
Lecture 17 - PHP-Object-Orientation.pptx
PDF
Advanced symfony Techniques
PDF
Refactoring using Codeception
PDF
Your Entity, Your Code
PDF
Your Entity, Your Code
PDF
Symfony2 Building on Alpha / Beta technology
Be RESTful (Symfony Camp 2008)
How Kris Writes Symfony Apps
Doctrine For Beginners
Unittests für Dummies
Separation of concerns - DPC12
How I started to love design patterns
Symfony tips and tricks
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
Lithium Best
Apostrophe
Unit testing after Zend Framework 1.8
Magento Live Australia 2016: Request Flow
Rich domain model with symfony 2.5 and doctrine 2.5
Lecture 17 - PHP-Object-Orientation.pptx
Advanced symfony Techniques
Refactoring using Codeception
Your Entity, Your Code
Your Entity, Your Code

More from Massimiliano Arione (18)

PDF
Typed models pug roma febbraio 2020
PPTX
Pipelines!
PDF
Il nostro amico Stan
PDF
PSR7 - interoperabilità HTTP
PDF
Disinstallare fos user bundle e vivere felici
PDF
MAGA - PUG Roma giugno 2017
PDF
PHP7 e Rich Domain Model
PDF
PHP on the desktop
PDF
Scrivere e leggere log con elastic
PDF
The metrics
PDF
Managing frontend libs in your Symfony project
PDF
Translating symfony docs
PDF
Managing frontend libs in your php project
PDF
Gestire librerie di frontend in php
ODP
Symfony: un framework per il web
PPT
symfony & jQuery (phpDay)
PPT
Symfony ignite
ODP
Phpcon2009 Php e Sicurezza
Typed models pug roma febbraio 2020
Pipelines!
Il nostro amico Stan
PSR7 - interoperabilità HTTP
Disinstallare fos user bundle e vivere felici
MAGA - PUG Roma giugno 2017
PHP7 e Rich Domain Model
PHP on the desktop
Scrivere e leggere log con elastic
The metrics
Managing frontend libs in your Symfony project
Translating symfony docs
Managing frontend libs in your php project
Gestire librerie di frontend in php
Symfony: un framework per il web
symfony & jQuery (phpDay)
Symfony ignite
Phpcon2009 Php e Sicurezza

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectral efficient network and resource selection model in 5G networks
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx

Migrare da symfony 1 a Symfony2