我需要在 symfony 2 上为我的网站实现 RESTful API,所以我使用 FOSRestBundle + JMSSerializerBundle
我的实体有这样的序列化器 yml:
Acme\DemoBundle\Entity\Product:
exclusion_policy: ALL
accessor_order: custom
custom_accessor_order: [id, title]
properties:
id:
expose: true
title:
expose: true
virtual_properties:
getMainPhoto:
serialized_name: photo
问题是getMainPhoto
返回我的网址全尺寸图像。我想在向 api 客户端发送响应之前预处理此 url,在其中我可以生成新的 url 来调整此类图像的大小版本。我已经在 sf2 中有可以完成这项工作的服务:
$resized_url = $someService->generateResizedUrl($item->getMainPhoto(), 640, 480);
但我不知道如何通过 JMSSerializer 使用此服务。也许在发送响应之前 FOSRestBundle\JMSSerializerBundle 有一些回调?
看一下文档 http://jmsyst.com/libs/serializer#documentation。您可以使用许多事件和/或注释来挂钩序列化过程。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)