[TYPO3-mvc] Best practice for ajax json_encode on repository of model

Domi djgarms at gmail.com
Mon Feb 18 05:15:28 CET 2013


Good Morning,

I would like to know best practice example for using ajax json calls on 
my extbase domain model.

I would like to make a list of all MailEntries via ajax call. So all I 
did is setting up typeNum and could make it work using the json 
type:html and render the fluid action getAllMailEntriesAction() into an 
html element <div id="mailEntries"></div>

So far everything went well.

Now I want to optimize the action and instead of rendering the whole 
html inside of fluid, I would like to get json and render the output via 
javascript.

I tried to do:
PHP
$mailEntries = 
$this->mailEntryRepository->getEmailsFromUser($this->user, $args['userId']);
return json_encode( $mailEntries->toArray() );

This results into an empty json array.

Is it possible to get my repository instance into a JSON where all my 
relations to other models are correctly printed out?

I found EncodeViewHelper in VHS - thanks Claus! - which looked very 
appealing. Is this the way to go for this matter or is there another 
way, like extbase utility tool, which converts my repository instance 
into a JSON directly inside of my controller? Then I wouldn't need to 
render any html which I guess would be faster.

All the best,

Dominic





More information about the TYPO3-project-typo3v4mvc mailing list