ObjectStorage不保存数据

时间:2017-06-14 09:59:30

标签: typo3 typo3-7.6.x

我有TYPO3版本7.6.18。

我无法在前端保存下拉字段,但我可以将其保存在后端。

TCA:

'glasses' => array(
    'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:tx_feusersplus_domain_model_user.glasses',
    'config' => array(
        'type' => 'select',
        'renderType' => 'selectMultipleSideBySide',
        'foreign_table' => 'tx_feusersplus_domain_model_glasses',
        'MM' => 'tx_feusersplus_user_glasses_mm',
        'foreign_table_where' => 'AND tx_feusersplus_domain_model_glasses.sys_language_uid=###REC_FIELD_sys_language_uid### ',
        'maxitems' => '50'
    ),
),

模特:

/**
 * glasses
 *
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Glasses>
  * 
 */
protected $glasses;

/**
 * Returns the glasses
 *
 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Glasses> $glasses
 */
public function getGlasses()
{
    return $this->glasses;
}

/**
 * Sets the glasses
 *
 * @return void
 */
public function setGlasses($glasses)
{
    $this->glasses = $glasses;
}

观点:

{namespace femanager=Fhk\Feusersplus\ViewHelpers}
<f:render section="default" arguments="{_all}" />

<f:section name="default">
    <div class="femanager_fieldset femanager_glasses control-group">
        <label for="femanager_field_glasses" class="control-label">
            <f:translate key="tx_feusersplus.glasses"/>
            <f:if condition="{femanager:Validation.IsRequiredField(fieldName:'glasses')}">
                <span>*</span>
            </f:if>
        </label>
        <div class="controls">
            <femanager:form.select
                id="femanager_field_glasses"
                property="glasses"
                options="{femanager:Form.GetGlasses()}"
                class="input-block-level"
                additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'glasses')}" />
        </div>
    </div>
</f:section>

我真的尝试了很多变种。清除所有缓存。它从后端起作用。请帮助我任何人)它不会节省在前端

1 个答案:

答案 0 :(得分:0)

您需要在model文件中为selectMultipleSideBySide选择框

添加以下方法
protected function initStorageObjects() {
    $this->glasses = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}


/**
 * Adds a glasses
 *
 * @param \Fhk\Feusersplus\Domain\Model\Glasses $glasses
 * @return void
 */
public function addglasses(\Fhk\Feusersplus\Domain\Model\Glasses $glasses) {
    $this->glasses->attach($glasses);
}

/**
 * Removes a glasses
 *
 * @param \Fhk\Feusersplus\Domain\Model\Glasses $glassesToRemove The Category to be removed
 * @return void
 */
public function removeglasses(\Fhk\Feusersplus\Domain\Model\Glasses $glassesToRemove) {
    $this->glasses->detach($glassesToRemove);
}

/**
 * Returns the glasses
 *
 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Glasses> $glasses
 */
public function getglasses() {
    return $this->glasses;
}

/**
 * Sets the glasses
 *
 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Glasses> $glasses
 * @return void
 */
public function setglasses(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $glasses) {
    $this->glasses = $glasses;
}

还有你的TCA和sql文件,如下所示。

glasses int(11) unsigned DEFAULT '0' NOT NULL,

    'glasses' => [
    'exclude' => true,
    'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:tx_feusersplus_domain_model_user.glasses',
    'config' => [
    'type' => 'select',
    'renderType' => 'selectMultipleSideBySide',
    'foreign_table' => 'tx_feusersplus_domain_model_glasses',
    'MM' => 'tx_feusersplus_user_glasses_mm',
    'size' => 10,
    'autoSizeMax' => 30,
    'maxitems' => 9999,
    'multiple' => 0,
    'wizards' => [
        '_PADDING' => 1,
        '_VERTICAL' => 1,
        'edit' => [
            'module' => [
                'name' => 'wizard_edit',
            ],
            'type' => 'popup',
            'title' => 'Edit', // todo define label: LLL:EXT:.../Resources/Private/Language/locallang_tca.xlf:wizard.edit
            'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_edit.gif',
            'popup_onlyOpenIfSelected' => 1,
            'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
        ],
        'add' => [
            'module' => [
                'name' => 'wizard_add',
            ],
            'type' => 'script',
            'title' => 'Create new', // todo define label: LLL:EXT:.../Resources/Private/Language/locallang_tca.xlf:wizard.add
            'icon' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_add.gif',
            'params' => [
                'table' => 'tx_drcbanners_domain_model_bannerscategories',
                'pid' => '###CURRENT_PID###',
                'setValue' => 'prepend'
            ],
        ],
    ],
],
],

uninstall / install分机后添加此更改并清除安装路费中的所有cache data