F
F
fman22020-11-09 14:26:46
PHP
fman2, 2020-11-09 14:26:46

Hydration of an entity from a request. What to use?

Hello.
Briefly: there is a legacy project in which Symfony components are embedded. There is Doctrine and Request.

Is there any builder that can put data into an entity from Request POST?
To avoid writing $entity->setName, setText and so on every time.
The data is essentially all simple, strings, yes numbers.

It seems that symfony/forms can do this, but we already have the layout of the forms.

Thanks to all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2020-11-09
@fman2

Use Symfony Serializer Component , namely built-in ObjectNormalizeror GetSetMethodNormalizer, once you decide to work with entities through setters / getters

$obj = $this->normalizer->denormalize($data, YourEntity::class);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question