2015-11-04 27 views
1

在我的擴展中,我讀取了文件夾和圖像。但在結果總是從sys_file_metadata元數據丟失,我什麼都沒有發現如何加載它。如何在Extbase中檢索FAL對象的元數據

數據庫條目在那裏,所以文件索引,一切似乎都沒問題。 BE工作正常。

這裏是一些代碼:

控制器,操作:

$storageId = 1; 
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository'); 
$storage = $storageRepository->findByUid($storageId); 
$singleFile = $storage->getFile('/user_upload/my_file.pdf'); 
$singleFile = true; 
$this->view->assign('singleFile', $singleFile); 

如果我做AF:調試它showns我:

Extbase Variable Dump 

TYPO3\CMS\Core\Resource\Fileprototypeobject 
    metaDataLoaded => FALSE 
    metaDataProperties => array(empty) 
    indexingInProgress => FALSE 
    updatedProperties => array(empty) 
    indexerService => NULL 
    properties => array(15 items) 
    storage => TYPO3\CMS\Core\Resource\ResourceStorageprototypeobject 
    identifier => '/user_upload/my_file.pdf' (24 chars) 
    name => 'my_file.pdf' (11 chars) 
    deleted => FALSE 

正如你可以看到有一個場metaDataProperties和metaDataLoaded,所以它沒有加載。

有人知道如何加載它嗎?

+0

其未加載的原因是因爲它的延遲加載;-) - >解決方案在 –

回答

5

你可以嘗試使用這種流體

{singleFile.properties.description}, {singleFile.properties.title} or {singleFile.properties.alternative}

或這一個獲得所有屬性

$singleFile->_getMetaData()

這也可以是有益的 $singleFile->getProperty('description')

+0

下面看到完美的答案!效果很好。我想知道爲什麼數據不包含在調試輸出中,並且您不必像控制集合那樣在控制器動作中顯式加載它們。 –

+0

這將是很好的文檔... :-) –

+0

閱讀相關文件的任何想法? –

0

對於閱讀相關文件(由「媒體」擴展程序提供) )一種解決方案將是以下代碼。這是爲了完成上述評論中的問題。

private function getRelatedFiles($fileId) { 
    $items = array(); 
    $resSub = 'SELECT sys_file_reference.uid_local '. 
     ' FROM sys_file_reference LEFT JOIN sys_file_metadata ON sys_file_reference.uid_foreign = sys_file_metadata.uid LEFT JOIN sys_file ON sys_file.uid = sys_file_metadata.file '. 
     ' WHERE sys_file.uid = '.$fileId; 

    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('sys_file.identifier', 
     'sys_file', 
     'sys_file.uid IN ('.$resSub.')' 
    ); 

    while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)){ 
     $items[] = $this->getDocumentStorage()->getFile($row['identifier']); 
    } 

    return $items; 
} 
相關問題