Skip to content

Instantly share code, notes, and snippets.

View piotrplenik's full-sized avatar

Piotr Plenik piotrplenik

View GitHub Profile
@piotrplenik
piotrplenik / New way to set the encoder.
Created December 31, 2011 19:04 — forked from damienalexandre/New way to set the encoder.
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'));