Skip to content

Instantly share code, notes, and snippets.

@damienalexandre
Created January 23, 2011 15:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save damienalexandre/792157 to your computer and use it in GitHub Desktop.
Save damienalexandre/792157 to your computer and use it in GitHub Desktop.
Playing with the Symfony2 serializer
<?php
// Inside your action
$this->serializer = new \Symfony\Component\Serializer\Serializer();
$this->serializer->addNormalizer(new \Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer());
$this->serializer->setEncoder('xml', new \Symfony\Component\Serializer\Encoder\XmlEncoder());
return $this->createResponse($this->serializer->encode($page, 'xml'), 200, array('Content-Type' => 'application/xml'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment