Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:38:30+00:00 2026-06-06T21:38:30+00:00

Consider the following scenario We have a simple database that involves two entities: user

  • 0

Consider the following scenario

We have a simple database that involves two entities: user and category.
For our hypothesis let’s say that a user can have only a type of category and a category can be associated with n users.

Now, consider a web page where a user – say ROLE_ADMINISTRATOR – could edit user table and associate them to a different one category.
As far I know (and I’m still new to symfony in general) if I use Doctrine and symfony2 in tandem, with – let’s say – annotation method, i’ll have two entity (php classes).


Embedded form
I will create a form that will show the user and, for show – and persist, of course! – also his category I “choose” to follow the “embedded form” strategy.
Having said that the entity has been created, i’ll have to create a form for category (suppose that into formBuilder I’ll add only id attribute of the category).
After that I have to add to formBuilder of UserType class the previous form and, with “some kind of magic” the form will render (after the appropriate operations) as magic and just as magically, when i’ll post it (and bind, and so on) back all the informations will be persists onto database

Data Transformers
A.K.A. trasnform an input of a form into an object and vice versa.
In that way I’ll have to define a – let’s say – CategorySelectorType that into his builder, will add a Class (service ?) that will do those transformations.
Now we define the data transformer itself that will implement the DataTransofmerInterface (with his method and so on…)
The next step will be register that entity into services and add into UserType the form that will use this service.


So I don’t understand any “strong” difference between those two metodology but “reusability” of the service. Somebody can offer me a different point of view and explain me the differences, if any?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:38:31+00:00Added an answer on June 6, 2026 at 9:38 pm

    A data transformer does not replace a embedded form, it rather enhances forms and wraps data transformation nicely.

    The first sentence on the cookbook page about Data Transformers sums it up nicely:

    You’ll often find the need to transform the data the user entered in a
    form into something else for use in your program.

    In your example above, you could add a drop-down list of categories so the admin can select one for the given user. This would be done using a embedded form. As the category field is the id of an existing category, there is no need to transform the data.

    For some reason you now want the admin to be able to enter a free text of the category. Now you need to do some tranformation of the text into the object in question. Maybe you want him to be able to either add a new or select a current category with this text field. Both is possible by using a data transformer which takes the text and searches for the category. Depending on your needs, not existing categories can be created and returned.

    Another use case is when a user enters data which needs to be modified in some way before storing them. Let’s say the user enters a street, house number and city but you want to store the coordinates instead.

    In both cases it doesn’t matter if you embed the form into another!

    Could you do that in your controller? Of course. Is it a good idea to do such things in the controller? Probably not, as you have a hard time testing (while doing it in the transformer let you unit test the transformation nicely) or reusing it.

    UPDATE

    Of course it is possible to place the transformation code someplace else. The user object itself is not a good place, as the model should not know about the entity manager, which is needed to do the transformation.
    The user type would be possible, but this means that it gets tied to the entity manager.

    It all adds up to the very powerfull concept of Separation of concerns, which states that one class should only do one thing to make it maintainable, resuable, testable and so on. If you follow this concept, than it should be clear that data transformation is a thing on its own and should be threated as such. If you don’t care, you may not need the transformation functionality.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following scenario: I have RESTful URL /articles that returns list of articles user
Let's consider the following scenario. I have the following page where all rendered elements
Consider the following scenario: I have two assemblies: Assembly named A.dll located in folder
please consider the following scenario for .net 2.0: I have an event that is
Consider the following scenario . I have an array of numbers: [ 1,2,3,4 ]
From couple of days i am thinking of a following scenario Consider I have
Let's consider the following scenario: a function which can generate code colors from white
Consider the following scenario. We have a C++ function with a static local variable:
consider the following scenario: I have a storyboard-based app. I add a ViewController object
Consider the following scenario: Someone has a project on Github that might be updated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.