Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonView seems not to work #6

Open
ghost opened this issue Dec 15, 2015 · 3 comments
Open

JsonView seems not to work #6

ghost opened this issue Dec 15, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 15, 2015

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>
@benjaminrau
Copy link

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(); } }

@xperseguers
Copy link
Owner

Is problem now fixed for you?

@jrenggli
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants