Skip to content

Instantly share code, notes, and snippets.

Created November 28, 2015 09:24
Show Gist options
  • Save anonymous/8faebd63309e565d26c6 to your computer and use it in GitHub Desktop.
Save anonymous/8faebd63309e565d26c6 to your computer and use it in GitHub Desktop.
ExportController & ExportJsonView
<?php
namespace VENDOR\Export\Controller;
class ExportController
extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* A list of formats and object names of the views which should render them
*
* @var array
*/
protected $viewFormatToObjectNameMap = [
'json' => \VENDOR\Export\View\Export\ExportJsonView::class
];
/**
* @var \VENDOR\MyExtension\Domain\Repository\CustomerRepository
* @inject
*/
protected $customerRepository;
/**
* Render the template
*
* @return void
*/
public function indexAction() {}
/**
* export action
*/
public function exportAction() {
$this->view->setVariablesToRender( ['pages'] );
$this->view->assign( 'pages', $this->pageRepository->findAll() );
$this->view->setConfiguration(
[
// Pages
'pages' => [
'_descend' => [
// Customer
'customer' => [
'_descendAll' => []
]
]
]
]
);
}
}
<?php
namespace VENDOR\Export\View\Export;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class ExportJsonView
extends \TYPO3\CMS\Extbase\Mvc\View\JsonView
{
/**
* Export path
*/
const EXPORT_FOLDER = PATH_typo3conf . 'ext/export/data/';
/**
* render function
*/
public function render() {
$propertiesToRender = $this->renderArray();
$export = json_encode( $propertiesToRender, JSON_PRETTY_PRINT );
GeneralUtility::writeFile(
self::EXPORT_FOLDER . 'data.json',
$export
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment