gpt4 book ai didi

symfony - JMSSerializerBundle 复杂生成值

转载 作者:行者123 更新时间:2023-12-04 15:45:59 26 4
gpt4 key购买 nike

我需要在 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 发送响应之前有一些回调?

最佳答案

看看the documentation .您可以使用许多事件和/或注释来 Hook 序列化过程。

关于symfony - JMSSerializerBundle 复杂生成值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14475171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com