Skip to content

Instantly share code, notes, and snippets.

@Chrysweel
Created August 2, 2013 13:07
Show Gist options
  • Save Chrysweel/6139735 to your computer and use it in GitHub Desktop.
Save Chrysweel/6139735 to your computer and use it in GitHub Desktop.
Serialize twice
My controller:
/**
* @ParamConverter("channel", class="ApiBundle:Channel")
*/
public function showAction(Channel $channel, Request $request)
{
$serializer = $this->container->get('serializer');
$channel = $serializer->serialize($channel, 'json', SerializationContext::create()->setGroups(array('list')));
$view = $this->view($channel, 200);
return $this->handleView($view);
}
My Entity:
class Channel
{
/**
* @var integer $id
* @Groups({"list", "details"})
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Groups({"list"})
* @var string $nombre
* @ORM\Column(name="nombre", type="string", length=255)
*/
private $nombre;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment