Answer the question
In order to leave comments, you need to log in
How to work with nested objects and forms in Symfony?
I am doing one project, and it has nested objects that need to be edited.
For example, the product class Product, it has a class with characteristics Specs, inside it there are other classes with descriptions of characteristics by categories: Common, Casing, Display... inside these classes are descriptions of parameters, and there can also be nested classes, for example, Specs - Camera - Sensors - an array of Sensor objects
It turns out something like this:
product:
- title
- series
- specs:
- common:
- releasedAt
- ...
- camera:
- sensors:
- [{resolution, aperture, pixelSize}, ...]
- ...
- ...
- ...
Answer the question
In order to leave comments, you need to log in
Forms do not work well with dynamic content, the best solution would be to move the form to the frontend, and use the serializer + validator + argument-resolver from the backend (see How to filter and map data when implementing an API on Symfony4? )
If you specs
always have the same set of objects and no dynamic parameters, then nested forms may well work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question