【发布时间】:2025-12-29 00:20:15
【问题描述】:
我的 TYPO3 中有一个名为 Location 的对象,用于存储有关城市的信息,包括 pdf 文件。
在后端,我可以毫无问题地上传 pdf,但是当我尝试显示它时,我得到 NULL。数据库中'pdf'的值不是NULL,但是当我调试<f:debug>{location}</f:debug>我得到pdf => NULL !!!
这是我的 TCA/位置:
$GLOBALS['TCA']['tx_locations_domain_model_location'] = array(
'ctrl' => $GLOBALS['TCA']['tx_locations_domain_model_location']['ctrl'],
....
'columns' => array(
...
'pdf' => array(
'exclude' => 1,
'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
'config' => array (
'type' => 'group',
'internal_type' => 'file',
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/pics',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1
)
),
...
Getter 和 Setter 在 typo3conf/ext/locations/Classes/Domain/Model/Location.php 中应该没问题:
/**
* Returns the pdf
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
*/
public function getPdf() {
return $this->pdf;
}
/**
* Sets the pdf
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
* @return void
*/
public function setPdf(\TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf) {
$this->pdf = $pdf;
}
您可以从下面看到调试给出 pdf=> NULL:
我的 pdf 栏不为空:
我错过了什么吗??
更新: 在 Pavin 的回答之后,我可以在 PDF 中看到一些东西,但是我无法在 href 标签中获取文件的名称,也许我需要在新的答案之后更改一些东西。 我可以看到数据库中的内容发生了变化,pdf 字段现在是布尔值。这就是为什么我可能会得到 pdf0.originalResource NULL,但在后端我可以上传文件并在保存和刷新后查看!!!:
<p><f:translate key="tx_locations_domain_model_location.downloadpdf" /> <a class="download" target="_blank" title="Initiates file download" href="{location.pdf.originalResource.publicUrl}"><f:translate key="tx_locations_domain_model_location.here" />..</a></p>
更新 2
我的新模型/Location.php
/**
* pdf
*
* @var string
*/
protected $pdf = NULL;
...
/**
* Returns the pdf
*
* @return string $pdf
*/
public function getPdf() {
return $this->pdf;
}
/**
* Sets the pdf
*
* @param string $pdf
* @return void
*/
public function setPdf($pdf) {
$this->pdf = $pdf;
}
我的 TCA/Location.php
'pdf' => array(
'exclude' => 1,
'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
'config' => array (
'type' => 'group',
'internal_type' => 'file',
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/pics',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1
)
),
【问题讨论】:
标签: typo3 typo3-6.2.x