2
我正在使用typo3 7.6。 我不能让我的自定义JSONView extbase,它似乎不认识它。Extbase无法识别自定义JsonView
我覆盖默认JsonView这样的:
use TYPO3\CMS\Extbase\Mvc\View\JsonView as ExtbaseJsonView;
class JsonView extends ExtbaseJsonView
{
/**
* @var array
*/
protected $configuration = [
'jobs' => [
'_exclude' => ['pid'],
'_descend' => [
'place' => [
'_only' => ['name']
]
]
],
];
}
编辑:根据这一docu
现在我不明白为什么我仍然得到这个输出JSON:
[{"description":"Owns products","pensum":100,"pid":55,"test":"Product","title":"Product Owner","uid":1}]
即使在排除字段中,该位置仍然存在,并且该位置不会被输出。看起来extbase忽略了我的重写,但我不知道为什么,也没有错误抛出。我把我的自定义JsonView成类/查看/ JsonView.php
我的车型有:
工作
/**
* Job
*/
class Job extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* title
*
* @var string
* @validate NotEmpty
*/
protected $title = '';
/**
* description
*
* @var string
*/
protected $description = '';
/**
* pensum
*
* @var int
*/
protected $pensum = 0;
/**
* test
*
* @var string
*/
protected $test = '';
/**
* place
*
* @var \Vendor\SfpJobs\Domain\Model\Place
*/
protected $place = null;
// below getter and setter
}
地方
/**
* Places
*/
class Place extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* name
*
* @var string
* @validate NotEmpty
*/
protected $name = '';
/**
* numberOfEmployees
*
* @var int
* @validate NotEmpty
*/
protected $numberOfEmployees = 0;
/**
* acquired
*
* @var \DateTime
* @validate NotEmpty
*/
protected $acquired = null;
// below getter and setter
}
控制器
/**
* JobAjaxController
*/
class JobAjaxController extends ActionController
{
/**
* @var string
*/
protected $defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
/**
* jobRepository
*
* @var \Vendor\SfpJobs\Domain\Repository\JobRepository
* @inject
*/
protected $jobRepository = NULL;
/**
* placeRepository
*
* @var \Vendor\SfpJobs\Domain\Repository\PlaceRepository
* @inject
*/
protected $placeRepository = NULL;
/**
* action list
* This function
*
* @param \Vendor\SfpJobs\Domain\Model\Job $job
* @return void
*/
public function listAction()
{
$jobs = $this->jobRepository->findAll();
$this->view->assign('jobs', $jobs);
$this->view->setVariablesToRender(array('jobs'));
}
}