t3ext-routing
t3ext-routing copied to clipboard
JsonView seems not to work
Either I am doing something wrong or the export via JsonView seems not to work. Each time I call my route the request returned a response with the content-type defined as text/html; charset=UTF-8 instead of application/json.
URLs to browse
http://app.dev/routing/block/api/list
or
http://app.dev/routing/block/api/list.json
Configuration/Routes.yaml
-
name: 'Demo action'
uriPattern: 'api/{@action}'
defaults:
'@package': 'VENDOR.Block'
'@plugin': 'Blockplugin'
'@controller': 'Block'
'@format': 'json'
or
-
name: 'Demo action'
uriPattern: 'api/{@action}.{@format}'
defaults:
'@package': 'VENDOR.Block'
'@plugin': 'Blockplugin'
'@controller': 'Block'
Both configurations and URLs are not working.
Classes/Controller/BlockController.php
<?php
namespace VENDOR\Block\Controller;
class BlockController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* @var \VENDOR\Block\Domain\Repository\BlockRepository
* @inject
*/
protected $blockRepository = NULL;
/**
* action list
*/
public function listAction() {
$blocks = $this->blockRepository->findByUid(1);
$this->view->assign('blocks', $blocks);
$this->view->setVariablesToRender(['blocks']);
}
}
Classes/View/Block/ListJson.php
<?php
namespace VENDOR\Block\View\Block;
class ListJson
extends \TYPO3\CMS\Extbase\Mvc\View\JsonView
{
protected $configuration = array(
'blocks' => [
'_descendAll' => []
]
);
}
Output
<html><head><style type="text/css"></style></head><body>{...}</body></html>
Same here - i think its because JsonView adds header to TypoScriptFrontendController in JsonView::L222 instead adding it to response directly.
Maybe because TSFE is initiated in eID script of EXT:routing but headers not parsed there?
I worked around like this (because i didnt understand the reason):
class JsonView extends \TYPO3\CMS\Extbase\Mvc\View\JsonView { public function render() { $response = $this->controllerContext->getResponse(); if ($response instanceof Response) { $response->setHeader('Content-Type', 'application/json'); } return parent::render(); } }
Is problem now fixed for you?
@xperseguers: I'm currently experiencing the same problem. PR from @SomeBdyElse basically fixed the issue.
Could you please release a new version of EXT:routing?