Skip to content
Advertisement

Best way or practice to assign values to array and then encode it to json in symfony

So currently I have this code:

JavaScript

And i’m getting this json response:

JavaScript

But I would like to get rid of id and weather from the json. Decoding and then encoding again seems like a bad way to do it. Can I access needed values before serializing them to json? I would like to get something like this:

JavaScript

Sorry if it’s a dumb question i’m still getting the ropes of symfony.

Advertisement

Answer

You won’t need to serialiaze your array of entities.

In your entity you can declare

JavaScript

And then call in your code, you can directly call json_encode on those entities:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement