[Flow] JSON data
Mark Kuiphuis
mark at capesso.com.au
Mon Jan 12 00:43:17 CET 2015
On 11/01/2015 6:28 pm, Garvit Khatri wrote:
> Hey everyone,
>
> How can I convert objects that i get from repository to json so that i can
> send json data back to my ajax request?
>
Hi Garvit,
I am normally using the standard PHP function json_encode($array);
For example you can do this in an Action inside your Controller:
$members = $this->memberRepository->findByProperty($property)->toArray();
return json_encode($members);
But I'm trying to imagine how your ajax success function is going to
look when you need to retrieve all the information in all objects from
the json response above....
If you know what "member" information you need, you can also do the
following:
$memberArray = array();
$members = $this->memberRepository->findByProperty($property);
if (count($members) > 0) {
foreach($members AS $member) {
$memberArray['firstName'] $member->getName()->getFirstName();
$memberArray['lastName'] = $member->getName()->getLastName();
...
...
}
}
return json_encode($memberArray);
More information about the Flow
mailing list