我需要在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将me url返回到全尺寸映像。我希望在向api客户端发送响应之前预先处理这个url,在那里我可以生成新的url来调整这类映像的大小。我已经在sf2中提供了服务,可以完成以下工作:
$resized_url = $someService->generateResizedUrl($item->getMainPhoto(), 640, 480);但是我不知道如何在JMSSerializer中使用这个服务。可能在发送响应之前,FOSRestBundle\JMSSerializerBundle有一些回调吗?
发布于 2013-01-23 10:21:47
看看文献资料。有许多事件和/或注释可以用来连接到序列化过程。
发布于 2013-04-29 21:02:39
可以排除原始url,然后使用system#序列化程序-后序列化事件添加调整大小的url。
当“产品”实例被序列化时,您必须编写侦听器。
https://stackoverflow.com/questions/14475171
复制相似问题