php - Symfony2 only use values from json_encode -


i'm getting information database , holding information in array. i've used {{dump(weights)}} in twig template, see below dump of array:

enter image description here

if use weights|json_encode() can information:

enter image description here

which okay, graph needs data in format - [69,72].

for example, how code should graph:

var geckoweight = {   labels: dates,   datasets: [     {       label: "front",       fillcolor: "rgba(0, 0, 0, 0.15)",       strokecolor: gradient,       pointcolor: gradient,       pointstrokecolor: "#202b33",       pointhighlightstroke: "rgba(225,225,225,0.9)",       data: [69,72]     }   ] }; 

what best way manipulate data suit needed in graph data?

i (in model method or controller):

class mycontroller extends controller {      public function someaction()     {         $data = array(             array('weight' => 69),             array('weight' => 72),         );         $graphdata = array_map(function($i) { return $i['weight']; }, $data);          return $this->render('default/index.html.twig', array(                        'data' => $weights,         ));     } 

on twig template:

<script>     var weights = {{ data|json_encode }}; </script> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -