我在TYPO3中有一个名为Location的对象,我存储有关城市的信息,包括pdf文件 . 在后端我可以毫无问题地上传pdf,但是当我尝试显示它时,我得到NULL . 数据库中'pdf'的值不是NULL,但是当我调试 <f:debug>{location}</f:debug>
时,我得到pdf => NULL!
这是我的TCA / LOCATION:
$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
)
),
...
typo3conf/ext/locations/Classes/Domain/Model/Location.php 中的Getter和Setter应该没问题:
/**
* 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;
}
您可以从下面看到debug给出pdf => NULL:
我的pdf列不为空:
我错过了什么 ??
UPDATE : 在Pavin的回答之后,我可以看到PDF中的内容,但我可以't get the name of the file in href tag , maybe I need to change something after the new answer. I can see things changed in the Database, the pdf field now is boolean. that'为什么我可能得到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>
UPDATE 2
我的新Model / 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
)
),
2 回答
您可以在以下TCA配置中使用
Doc
类型记录 . 还在模型文件中添加Getter和Setter方法 .对于 Model.php 文件 .
initStorageObjects 方法:
Getter And Setter Method :
有关pdf名称,请参阅附图 . 请添加pdf Headers . 对于Pdf Headers ,您可以使用
{location.pdf.title}
您使用
group
作为在TCA中保存文件的类型,因此模型中的属性$pdf
必须是string
而不是\TYPO3\CMS\Extbase\Domain\Model\FileReference
FileReference仅适用于FAL(文件抽象层)