내가 데이터를 얻기 위해 몽고의 ODM 쿼리를 사용하지만 난 그것을 배열 형식으로 반환 쿼리 데이터를 얻을 수 있지만, 내가 JSON으로 배열에서 데이터를 변환하는 방법을 JSON 형식으로 데이터를 얻을 할 때 여기 내 코드입니다 :zf2에서 json으로 배열의 데이터를 변환하는 방법은 무엇입니까?
public function loadAction()
{
$response = $this->getResponse();
$id = (int) $this->params()->fromRoute('id', 0);
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$calendars = $dm->createQueryBuilder('Calendar\Document\Event')
->hydrate(false)
->field("calendar_id")->equals($id)
->getQuery()->execute();
$array = array();
if($calendars && !is_null($calendars) && is_object($calendars)){
foreach($calendars as $key=>$value) {
$array[] = $value;
}
}
echo "<pre>";
print_r($array);
echo "</pre>";
return $response;
//return $this->getResponse()->setContent(Json::encode($array));
}
여기 내 반응이다 :
Array
(
[0] => Array
(
[_id] => 11
[calendar_id] => 44
[title] => fhfhfhfhfhfhfhf
[description] => hfhfhfhfhffh
[begin] => MongoDate Object
(
[sec] => 1397744580
[usec] => 0
)
[end] => MongoDate Object
(
[sec] => 1403187780
[usec] => 0
)
)
[1] => Array
(
[_id] => 12
[calendar_id] => 44
[title] => fhfhfhfhfhfhfhfdgdg
[description] => hfhfhfhfhffhdgdgdg
[begin] => MongoDate Object
(
[sec] => 1397744580
[usec] => 0
)
[end] => MongoDate Object
(
[sec] => 1403360580
[usec] => 0
)
)
[2] => Array
(
[_id] => 13
[calendar_id] => 44
[title] => xvxvxvxv
[description] => czzzvxvvzxvxvzxv
[begin] => MongoDate Object
(
[sec] => 1398349380
[usec] => 0
)
[end] => MongoDate Object
(
[sec] => 1403706180
[usec] => 0
)
)
[3] => Array
(
[_id] => 14
[calendar_id] => 44
[title] => xvxvxvxggjgjfj
[description] => czzzvxvvzxhhdfhhd
[begin] => MongoDate Object
(
[sec] => 1398349380
[usec] => 0
)
[end] => MongoDate Object
(
[sec] => 1403706180
[usec] => 0
)
)
[4] => Array
(
[_id] => 15
[calendar_id] => 44
[title] => xvxvxvxggjgjfjsadgggggggfdhdfhhdh
[description] => czzzvxvvzxhhdfhhddghhffffffffffffff
[begin] => MongoDate Object
(
[sec] => 1398349380
[usec] => 0
)
[end] => MongoDate Object
(
[sec] => 1404138180
[usec] => 0
)
)
)
하지만 난이 형식으로 DAT를 원하는 :
[{
"event_id":"2",
"calendar_id":"1",
"author_id":"1",
"title":"Launch",
"description":"Launch Break",
"begin":"2014-03-02 20:00:00",
"end":"2014-03-31 16:53:00",
"calendar_title":"Hijri Calender",
"author_email":"[email protected]"
}]
json 형식 –