【问题标题】:TYPO3 Extbase JsonView FALTYPO3 Extbase JsonView FAL
【发布时间】:2016-10-04 15:51:40
【问题描述】:

这是我的控制器动作:

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

【问题讨论】:

  • 能分享一下Produkt的相关模型零件吗?
  • 好的,在上面编辑。希望这是正确的部分。
  • 我怀疑这与文件和文件引用对象的属性不是真正的对象属性,而是存储为延迟加载的关联数组(我认为名为@9​​87654324@)有关。 JsonView 只处理它可以通过调用get_object_vars(通过调用getGettablePropertyNames())获得的那些,它使用get_object_vars。尝试输出属性properties,也许有帮助?不确定这是否正确。

标签: json controller typo3 extbase


【解决方案1】:

尝试下降到FileReferenceoriginalResource 并暴露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');
                                );
                            );
                        );
                    ),
                )
            )
        )
    )
);

【讨论】:

  • 谢谢,我试试。但不幸的是没有效果。只有 PID 和 UID。
  • 请在Produkt 上执行DebuggerUtility:var_dump(可能为此目的停用JsonView),例如调试第一项 ($this->produktRepository->findAll()->getFirst()) 并查看属性 originalResource 是否在那里工作
【解决方案2】:

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 仍然有效。

【讨论】:

    【解决方案3】:

    尝试使用 \TYPO3\CMS\Extbase\Persistence\ObjectStorage 而不是 \TYPO3\CMS\Extbase\Domain\ Model\FileReference 用于您的模型中的 FAL 属性。 我不需要多个文件,但是在我更改此文件后,我得到了 publicUrl。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 2020-08-06
      • 2015-08-05
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      相关资源
      最近更新 更多