[英]TYPO3 Extbase JsonView FAL
这是我的控制器动作:
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-String。 不幸的是,我仅获得包含文件(FAL)的PID和UID。 如何获取完整对象或至少包含文件的路径?
/**
* 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;
}
尝试下降到FileReference
的originalResource
并公开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');
);
);
);
),
)
)
)
)
);
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
。
对于模型中的FAL属性,请尝试使用\\ TYPO3 \\ CMS \\ Extbase \\ Persistence \\ ObjectStorage <\\ TYPO3 \\ CMS \\ Extbase \\ Domain \\ Model \\ FileReference>,而不是\\ TYPO3 \\ CMS \\ Extbase \\ Domain \\ Model \\ FileReference 。 我不需要多个文件,但是在更改了此文件后,我得到了publicUrl。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.