2016-10-04 133 views
1

这是我的控制器动作: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字符串。不幸的是,我只能得到包含文件(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; 
} 
+0

您是否可以分享Produkt的相关型号零件? – lorenz

+0

好的,上面编辑。希望它是正确的部分。 – hydrococcus

+0

我怀疑这必须与文件和文件引用对象的属性不是真正的对象属性,但存储为延迟加载关联数组(我认为名为'属性')。 'JsonView'只处理通过调用'get_object_vars'(通过调用[getGettablePropertyNames()](https://typo3.org/api/typo3cms/_object_access_8php_source.html#l00232))获得的结果,该结构使用' get_object_vars'。尝试输出属性'属性',也许有帮助?不知道这是否正确。 – Jost

回答

2

尝试下降到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'); 
           ); 
          ); 
         ); 
        ), 
       ) 
      ) 
     ) 
    ) 
); 
+0

谢谢,我尝试过。但不幸的是没有效果。只有PID和UID。 – hydrococcus

+0

请在'Produkt'上执行'DebuggerUtility:var_dump'(也许是为此目的不活动的JsonView),例如调试第一个项目('$ this-> produktRepository-> findAll() - > getFirst()')并查看'originalResource'属性是否在那里工作 – lorenz

0

originalResource部分是一个计算的属性,在调用消气方法的实体将被自动检索 - 这是它的在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