Skip to content

Instantly share code, notes, and snippets.

@fzaninotto
Created March 9, 2011 15:16
Show Gist options
  • Select an option

  • Save fzaninotto/862369 to your computer and use it in GitHub Desktop.

Select an option

Save fzaninotto/862369 to your computer and use it in GitHub Desktop.
<?php
// Propel way
$books = BookQuery::create()->find();
$xmlBooks = $books->toXml();
// Doctrine way
// $this is a symfony controller having access to the DIC
$em = $this->get('doctrine.orm.entity_manager');
$books = $em->createQuery('select b from \Acme\DemoBundle\Entity\Book b')->getResult();
$serializer = new \Symfony\Component\Serializer\Serializer();
$serializer->addNormalizer(new \Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer());
$serializer->setEncoder('xml', new \Symfony\Component\Serializer\Encoder\XmlEncoder());
$xmlBooks = $serializer->serialize($books, 'xml');
@kriswallsmith
Copy link
Copy Markdown

Yes, I'm not familiar with the Serializer component, but the configuration would look similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment