首页 文章

TCA property 不起作用

提问于
浏览
1

我在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:

See here

我的pdf列不为空:

See here

我错过了什么 ??

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,但在后端我可以上传文件,然后在保存和刷新后看到!!!:

enter image description here

<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>

enter image description here

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 回答

  • 0

    您可以在以下TCA配置中使用 Doc 类型记录 . 还在模型文件中添加Getter和Setter方法 .

    'pdf' => array(
        'exclude' => 0,
        'label' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang_db.xlf:label_key.files',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'pdf',
            array('minitems' => 0,'maxitems' => 10),
            'pdf,doc,docx'
        ),
    ),
    

    对于 Model.php 文件 .

    /**
         * pdf
         *
         *@var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
         */
        protected $pdf;
    

    initStorageObjects 方法:

    protected function initStorageObjects() {
            $this->files = new ObjectStorage();
            parent::initializeObject();
        }
    

    Getter And Setter Method

    /**
         * Returns the pdf
         *
         * @return ObjectStorage
         */
        public function getPdf() {
            return $this->pdf;
        }
    
        /**
         * Sets the pdf
         *
         */
        public function setPdf($pdf) {
            $this->pdf = $pdf;
        }
    

    有关pdf名称,请参阅附图 . 请添加pdf Headers . 对于Pdf Headers ,您可以使用 {location.pdf.title}
    enter image description here

  • 1

    您使用 group 作为在TCA中保存文件的类型,因此模型中的属性 $pdf 必须是 string 而不是 \TYPO3\CMS\Extbase\Domain\Model\FileReference

    FileReference仅适用于FAL(文件抽象层)

相关问题