[Flow] JSON data
Christian Loock
brainshack at gmail.com
Mon Jan 12 07:46:21 CET 2015
To render json in your controller, there is a View Class dedicated to this.
http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/ModelViewController.html#json-view
You will just have to assign an object to a view variable and flow will
handle the rest for you. You can configure, wich variables of the object
are being rendered etc. Just look into the link provided above, it should
give you a good start.
2015-01-12 0:43 GMT+01:00 Mark Kuiphuis <mark at capesso.com.au>:
> 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);
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>
More information about the Flow
mailing list