[TYPO3-mvc] Best practice for ajax json_encode on repository of model
Tobias Liebig
tobias.liebig at typo3.org
Tue Feb 19 08:55:51 CET 2013
Hej,
when you want to jsonencode extbase objects, you might want to have a look at the MarshallService of EXT:tool by Claus Due.
https://github.com/NamelessCoder/tool/blob/master/Classes/Service/MarshallService.php
regards
tobias
Am 18.02.2013 um 20:35 schrieb Ludwig Rafelsberger <ludwig.rafelsberger at gmx.at>:
> Hi Dominic,
>
>> PHP
>> $mailEntries =
>> $this->mailEntryRepository->getEmailsFromUser($this->user,
>> $args['userId']); return json_encode( $mailEntries->toArray() );
>>
>> This results into an empty json array.
>
> When encoding your extbase objects, the native PHP function
> json_encode() will not consider protected attributes - which you
> probably are using. You might implement a simple "serialize" method
> in your objects, producing a suitable (associative, nested) array. Or
> have a look at the JsonSerializable interface*.
>
> Cheers,
> Ludwig
>
> [*]
> http://www.php.net/manual/en/class.jsonserializable.php
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
--
Tobias Liebig
TYPO3 Core Team member
TYPO3 .... inspiring people to share!
Get involved: typo3.org
http://bit.ly/supportTYPO3
More information about the TYPO3-project-typo3v4mvc
mailing list