Skip to content

Instantly share code, notes, and snippets.

@arnekolja
Created January 10, 2015 19:05
Show Gist options
  • Save arnekolja/ee9152e15e8f440773ad to your computer and use it in GitHub Desktop.
Save arnekolja/ee9152e15e8f440773ad to your computer and use it in GitHub Desktop.
TYPO3, Extbase: Simple JsonView usage
<?php
/* This is tested with 6.2.9 only */
namespace MY\Extension\Controller;
class MyController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
private $ajaxPageType = 133799;
/**
* myRepository
*
* @var \MY\Extension\Domain\Repository\LocationRepository
* @inject
*/
protected $myRepository = NULL;
/**
* action list
*
* @return void
*/
public function listAction() {
global $TSFE;
$items = $this->myRepository->findAll();
if ($TSFE->type == $this->ajaxPageType) {
$theView = $this->objectManager->get("\\TYPO3\\CMS\\Extbase\\Mvc\\View\\JsonView");
$theView->setControllerContext($this->controllerContext);
$theView->assign('items', $items);
$theView->setVariablesToRender(array('items'));
return $theView->render();
}
$this->view->assign("items", $items);
}
}
/*
# TypoScript for page type:
MyExtensionAJAX = PAGE
MyExtensionAJAX {
typeNum = 133799
config {
disableAllHeaderCode = 1
xhtml_cleaning = 0
admPanel = 0
additionalHeaders = Content-type: application/json
# no_cache = 1
debug = 0
}
10 < tt_content.list.20.my_extension
}
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment