Symfony Restful Post:JMSSerializerBundle与Symfony表单组件 [英] Symfony Restful Post: JMSSerializerBundle vs Symfony Form Components

查看:78
本文介绍了Symfony Restful Post:JMSSerializerBundle与Symfony表单组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,当控制器收到发布/发布/补丁请求时,JMSSerializerBundle的反序列化与symfony表单组件相同吗?

As far as i understand it right JMSSerializerBundle's deserialisation does the same same as the symfony form component when a controller gets an post/put/patch request?

所以我要么为例如创建一个symfony自定义formType.一个UserType,当我收到请求时,我会执行类似$ form-> handleRequest($ request)的操作,或者使用JMSSerializerBundle将请求反序列化为最终存储的文档/实体.

So either i create a symfony custom formType for e.g. an UserType and when i get a request i do something like $form->handleRequest($request) or i use JMSSerializerBundle to unserialize the request to a document/entity which gets finally stored.

有人对这两种方法都有经验吗?目前,我只熟悉表单方式...我应该选择哪一种?

Does anyone have experience with both methods? Currently i'm only familiar with the form way... Which one should i choose?

我正在谈论的应用程序纯粹是Restful,没有树枝HTML模板,而FOSRestbundle正在执行所有RESTful路由.

The Application i'm talking about is purely Restful, there are no twig html templates and FOSRestbundle is doing all the RESTful routing.

推荐答案

在我们的restfull API中,我们通常使用 Symfony序列化程序组件处理实体的反序列化,然后

In our restfull API we usually use the Symfony Serializer component to handle the deserialization of entities, then the Symfony Validator component to ensure that the entities fulfill all the required conditions before pushing/updating them in database. Works pretty well, lighter than the form component.

无论如何,Form组件将无法反序列化json/xml,因此您必须使用序列化程序.

Anyway The Form component would not be able to deserialize the json/xml so you'll have to use a serializer.

这篇关于Symfony Restful Post:JMSSerializerBundle与Symfony表单组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆