使用Extbase插件,我想顯示文件下載鏈接。 我使用typo3 v6.1 FAL文件結構。 但我無法獲得原始文件下載鏈接。Typo3 extbase FAL文件下載
在文件ext_tables.sql
CREATE TABLE tx_myext_domain_model_test (
# ...
files varchar(255) DEFAULT '' NOT NULL,
# ...
);
在文件配置/ TCA/test.php的
$TCA['tx_myext_domain_model_test'] = array(
// ...
'files' => array(
'exclude' => 1,
'label' => 'Files',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('files', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
),
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
),
// ...
);
在文件中的類/域/型號/ test.php的
class Test extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
// ...
/**
* Files
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
protected $files;
/**
* Returns the files
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $files
*/
public function getFiles() {
return $this->files;
}
}
在文件類/控制器/ TestController.php
class TestController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
// ..
public function listAction() {
$tests = $this->testRepository->findAll();
$this->view->assign('tests', $tests);
}
// ..
}
在文件資源/個人/模板/測試/ List.html
<f:for each="{tests}" as="test" iteration="itemIterator">
<f:debug title="Debug of test">{test.files}</f:debug>
<f:for each="{test.files}" as="file">
<a href="{f:uri.image(src:file.uid,treatIdAsReference:1)}">
<f:image src="{file.uid}" alt="" width='101' height="67" treatIdAsReference="1"/>
</a>
<p>{file.originalResource.originalFile.title}</p>
</f:for>
這裏如果在調試 「originalResource」 爲NULL。 有人知道如何獲得原始文件鏈接? 謝謝。
由於這是文件引用,您可能需要解析引用。 – pgampe
爲什麼你需要originalResource屬性?你想獲得文件的標題嗎?原始文件鏈接是什麼意思? – Shufla
嗨Shufla,我需要獲得文件名和文件路徑,所以可以使用href標籤下載文件。我的意思是原始文件鏈接意味着存儲在sys_file表中的文件路徑。所以我可以將該鏈接包裝在一個href標籤中。 –