Created
January 10, 2015 19:05
-
-
Save arnekolja/ee9152e15e8f440773ad to your computer and use it in GitHub Desktop.
TYPO3, Extbase: Simple JsonView usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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