I'm attempting to open up data from a PHP Object (as shown below) but I'd like to be able to access this data within JavaScript to use in a graphing library.
Object in question:
What I need to be able to do is convert that into a JSON encoded object for use within Javascript.
I tried using twig within Symfony to do this via:
{% set playerStats = match.getStatsPlayers().getValues() }%
{% dump(playerStats) %} // This is what you see above
var playerStats = {{ playerStats|json_encode }};
console.log(playerStats);
The console shows this:
Which is where I'm banging my head against the wall. Where can I access the values of these properties?
As an inefficient way, I've managed to get it into a JavaScript object by doing:
{% for p in playerStats %}
playerStats.push({ 'id': {{p.playerID}}, 'playerName': '{{p.playerName}}', 'playerOutfit': {{p.playerOutfit}}, 'playerFaction': {{p.playerFaction}}, 'playerKills': {{p.playerKills}}, 'playerDeaths': {{p.playerDeaths}}, 'playerTeamKills': {{p.playerTeamKills}}, 'playerSuicides': {{p.playerSuicides}} });
{% endfor %}
I feel kinda dirty for doing that. There must be a better way to do this surely?
Thanks in advance!