[TYPO3-mvc] Json View Output

Franz Koch typo3.RemoveForMessage at elements-net.de
Tue Feb 22 18:44:35 CET 2011


Hey,

...
> Controller:
> ====================================
> $this->view->setTemplateType('json'); //
> $this->view->assign('jsonData', $myArrayOrObject);
>
> Template (actionName.json):
> ====================================
> {jsonData}
> ...
>
> Is there any another way?

if your view does nothing more than simply returning a prepared 
jsonObject, then easiest might be to simply return the jsonObject in 
your action and not use any view.

public function yourAction() {
   ...
   return $myArrayOrObject;
}

But probably better/nicer might be to create a jsonViewObject that's 
doing the conversion for you and sending suitable headers etc.
-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list