Markdown

[PHP]Serializer


   use Symfony\Component\Serializer\SerializerInterface;~
   use Symfony\Component\Serializer\Encoder\XmlEncoder;~
   use Symfony\Component\Serializer\Encoder\JsonEncoder;~
   use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;~
   use Symfony\Component\Serializer\Serializer;~




  66 ~
- 67         $encoders = array(new XmlEncoder(), new JsonEncoder());~
2 68         $normalizers = array(new ObjectNormalizer());~
2 69 ~
2 70         $serializer = new Serializer($normalizers, $encoders);~
2 71 ~
2 72         $json = $serializer->serialize($messages, 'json');~


還要修改 app/service.yml  跟 route.yml annoation 

留言