TYPO3 Extbase JsonView FAL
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
.
在 Flow documentation 中找到更多详细信息,这对 TYPO3 CMS 中的 JsonView
仍然有效。
尝试使用 \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> 而不是 \TYPO3\CMS\Extbase\Domain\Model\FileReference 作为您的 FAL 属性在你的模型中。
我不需要一个以上的文件,但在我更改此文件后,我得到了 publicUrl。
这是我的控制器操作:
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
.
在 Flow documentation 中找到更多详细信息,这对 TYPO3 CMS 中的 JsonView
仍然有效。
尝试使用 \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> 而不是 \TYPO3\CMS\Extbase\Domain\Model\FileReference 作为您的 FAL 属性在你的模型中。 我不需要一个以上的文件,但在我更改此文件后,我得到了 publicUrl。