Answer the question
In order to leave comments, you need to log in
How to add field to entity Doctrine during serialization?
I use the common FosRestBundle for the site api. It uses the JMS Serializer by default. You need to add a calculated field to the entity Doctrine which is returned via api. This is the URI of the image on the server. The addresses of pictures are not stored in the database, but are generated dynamically by a separate Service.
Previously, I wrote a Listener, connected the Service in it and supplemented the output of the entity with the necessary information
$visitor = $event->getVisitor();
$visitor->addData('image_thumb', $thumbUrl);
Answer the question
In order to leave comments, you need to log in
Removed deprecated method JsonSerializationVisitor::addData, use :visitProperty(new StaticPropertyMetadata('', 'name', null), 'value') instead
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question