In my database I have an entity named Graphique. This the schema for:
class Graphique
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var decimal
*
* @ORM\Column(name="index", type="decimal", precision=9, scale=3, nullable=false)
*/
private $index;
/**
* @var datetime
*
* @ORM\Column(name="date", type="datetime", nullable=false)
*/
private $date;
/*getters and setters*/
This is some values for index, according to my database schema (example):
----------------------------------
id | index | dateTime |
----------------------------------
1 | 1700.000 | dateTime datas|
----------------------------------
2 | 1200.000 | dateTime datas|
----------------------------------
3 | 1200.000 | dateTime datas|
----------------------------------
4 | 1304.000 | dateTime datas|
----------------------------------
etc...| etc... | etc... |
I have this method into a controller:
$em=$this->getDoctrine()->getManager();
$queryIndex = $em->createQuery( 'SELECT g.index
FROM MySpaceMyBundle:Graphique g');
$array = array_map('current', $queryIndex);
$response = new Response();
$data = json_encode($array);
$response->headers->set('Content-Type', 'application/json');
$response->setContent($data);
return $response;
it returns me this into my json response:
["1700.000","1200.000","1200.000","1304.000","1800.000","2012.000","2048.000","1048.000","3000.000","5421.000"]
but I need to have this simple array result (instead the json response I give you just above):
[1700.000,1200.000,1200.000,1304.000,1800.000,2012.000,2048.000,1048.000,3000.000,5421.000]
I need to return a simple array in my json response in order to have this decimal values for displaying them into a highchart graphic.
How can I proceed? I already try some Doctrine methods like ->getArrayresult(), ->getScalarResult(), ->toArray(), but the results are the same. I need to make my query result to a simple array.