Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

Migrare da symfony 1 a Symfony2

  1. Migrare da symfony 1 a Symfony2 Massimiliano Arione @garakkio Torino, 5 ottobre 2012
  2. symfony 1 end of life: nov. 2012
  3. cosa non è Symfony 2
  4. cosa non è Symfony 2
  5. cosa è Symfony2
  6. Dependency Injection Container
  7. come funziona il DIC <?php $mailer = $this->get('mailer');
  8. come funziona il DIC <?php $mailer = $this->get('mailer'); niente più sfContext!
  9. 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; } }
  10. 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; } }
  11. test
  12. model
  13. model $ app/console doctrine:mapping:import AcmeMyBundle annotation $ app/console doctrine:generate:entities AcmeMyBundle --no-backup
  14. 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; }
  15. alcuni bundle da aggiungere stof/doctrine-extensions-bundle friendsofsymfony/user-bundle sonata-project/doctrine-orm-admin-bundle
  16. alcuni bundle da aggiungere stof/doctrine-extensions-bundle (sf1: behaviours) friendsofsymfony/user-bundle (sf1: sfGuardPlugin) sonata-project/doctrine-orm-admin-bundle (sf1: admin generator)
  17. 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, ); }
  18. 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(), ); }
  19. /** * @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(), ); }
  20. 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 %}
  21. cache http
  22. domande?
  23. 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/
Advertisement