这是我的主计长行动:
public function jsonAction()
{
$this->view->setVariablesToRender(array('produkte'));
$this->view->setConfiguration(
array(
'produkte' => array(
'_descendAll' => array(
'only' => array('titel', 'beschreibung', 'bild', 'download', 'categories'),
'_descend' => array(
'bild' => array(),
'download' => array(),
'categories' => array(),
)
)
)
)
);
$this->view->assign('produkte', $this->produktRepository->findAll());
}我得到了一个很好的JSON字符串。不幸的是,我只得到PID和包含文件的UID (FAL)。我如何才能获得完整的对象,或者至少是包含的文件的路径?
/**
* Returns the bild
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $bild
*/
public function getBild()
{
return $this->bild;
}
/**
* Returns the download
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $download
*/
public function getDownload()
{
return $this->download;
}发布于 2016-10-05 08:02:47
尝试降至FileReference的FileReference并公开publicUrl
$this->view->setConfiguration(
array(
'produkte' => array(
'_descendAll' => array(
'only' => array('titel', 'beschreibung', 'bild', 'download', 'categories'),
'_descend' => array(
'download' => array(
'_descendAll' => array(
'_only' => array('originalResource');
'_descend' => array(
'originalResource' => array(
'_only' => array('publicUrl');
);
);
);
),
)
)
)
)
);发布于 2016-10-10 12:04:52
originalResource部分是一个计算属性,在调用getter(将自动检索该实体的方法)时,它是如何在Extbase的FileReference模型中实现的。
/**
* @return \TYPO3\CMS\Core\Resource\FileReference
*/
public function getOriginalResource()
{
if ($this->originalResource === null) {
$this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($this->getUid());
}
return $this->originalResource;
}但是,请确保编写正确的JSON视图配置。所有与控件相关的属性都是带有下划线_的前缀--在上面的代码示例中,它应该是_only而不是only。有效的控制-名称是_only,_exclude,_descend,_descendAll,_exposeObjectIdentifier,_exposedObjectIdentifierKey,_exposeClassName.
在流程文档中可以找到更多细节,这对于JsonView在TYPO3 CMS中仍然有效。
发布于 2018-10-10 15:04:56
尝试使用\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>代替\TYPO3 3\CMS\Extbase\Domain\ Model \FileReference对模型中的FAL属性。我不需要多个文件,但在我改变这个文件后,我得到了publicUrl。
https://stackoverflow.com/questions/39856738
复制相似问题