TYPO3 Extbase - 无法通过 typnum 呈现 json

TYPO3 Extbase - Failing to render json via typnum

TYPO3 Extbase - 无法通过 typnum

呈现 json

在 list/edit/new/remove 操作(有效)旁边,我尝试在 json 中呈现输出。但是没有值呈现。如果我做一个简单的...

$data = array('value'=>'001');
return json_encode($data);

确实如此 return ...

{"value":"001"}

我错过了什么?

编辑: 使用并引用同一个存储库它的工作:

JSONController.php

<?php
namespace Vendor\Lei\Controller;
use Vendor\Lei\Domain\Model\Lei;

/**
 * JSONController
 */
 class JSONController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

/**
 * leiRepository
 *
 * @var \Vendor\Lei\Domain\Repository\LeiRepository
 * @inject
 */
protected $leiRepository;

/**
 * @var string
 */
protected $defaultViewObjectName = 'TYPO3\CMS\Extbase\Mvc\View\JsonView';

/**
 * action jsonRequest
 *
 * @return void
 */
public function jsonRequestAction() {

    //$data = array('value'=>'001');
    //return json_encode($data);

    $this->view->setVariablesToRender(array('records'));
    $this->view->assign('records', $this->leiRepository->jsonRequest());

}           

}

LeiRepository.php

<?php
namespace Vendor\Lei\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;

class LeiRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {

...

public function jsonRequest() {

    $query = $this->createQuery();
    $result = $query->setLimit(100)->execute();
    return $result;

}

}

如果您注入并使用 JsonRepository extbase expexts 一个名为 Json 的域对象。如果您只想将已经存在的域对象呈现为它们的 JSON 表示,只需使用您在 listAction()detailAction().

中使用的相同存储库

看看我的例子:https://usetypo3.com/json-view.html

此外,return 之后的调试将永远不会执行,就像您在存储库中所做的那样。