str*_*ker 6 symfony fosrestbundle jmsserializerbundle
我需要在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
Run Code Online (Sandbox Code Playgroud)
问题是getMainPhoto返回我的网址到完整大小的图像.我希望在向api客户端发送响应之前预处理此URL,我可以生成新的url来调整此类映像的大小.我已经在sf2中有服务可以完成这项工作:
$resized_url = $someService->generateResizedUrl($item->getMainPhoto(), 640, 480);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在JMSSerializer中使用此服务.也许在发送响应之前有一些FOSRestBundle\JMSSerializerBundle的回调?
| 归档时间: |
|
| 查看次数: |
1845 次 |
| 最近记录: |