TYPO3 Extbase JsonView FAL

时间:2016-10-04 15:51:41

标签: json controller typo3 extbase

这是我的控制器操作:

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;
}

3 个答案:

答案 0 :(得分:5)

尝试下降到originalResource的{​​{1}}并公开FileReference

publicUrl

答案 1 :(得分:0)

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

答案 2 :(得分:0)

尝试使用 \ TYPO3 \ CMS \ Extbase \ Persistence \ ObjectStorage <\ TYPO3 \ CMS \ Extbase \ Domain \ Model \ FileReference> 代替 \ TYPO3 \ CMS \ Extbase \ Domain \ Model \ FileReference 中的FAL属性。 我不需要一个以上的文件,但是更改此文件后,我得到了publicUrl。