【问题标题】:Multiple Select not working since upgrade to TYPO3 6.2 extbase升级到 TYPO3 6.2 extbase 后,多项选择不起作用
【发布时间】:2016-10-24 18:56:31
【问题描述】:

我刚刚检查过,在使用 TYPO3 4.7 的工作版本中,html 输出似乎与此相同
我有一个可以有多个学生的约会。我通过自动完成文本输入字段将它们添加到多选中。

<input type="text" id="student-autocomplete"/>
<br/>
<f:form.select  id="selected-students" 
                multiple="true" 
                property="students"
                options="{appointment.students}" 
                optionLabelField="fullName"
                class="" />

这是输出 - 在此示例中,我添加了两个学生。
输入隐藏字段似乎是由流体(?)自动生成的:

<input type="hidden" value="" name="tx_extname_appoints[appointment][students]">
<select id="selected-students" name="tx_extname_appoints[appointment][students][]" multiple="true">
<option value="160">student1</option>
<option value="52">student 2</option>
</select>

现在我真正不明白的是: 当我的选择中只有一个学生时它可以工作,但是当我有多个时,我会收到以下错误:

Caught exception: Exception while property mapping at property path "students":It is not allowed to map property "1". You need to use $propertyMappingConfiguration->allowProperties('1') to enable mapping of this property. 

我假设“1”指的是我的第二个数组索引?但我不知道出了什么问题,因为它似乎在 TYPO3 4.7 中运行良好。
我应该用 new 属性映射器做点什么?
我应该尝试更改模型中的某些内容吗?

/**
* students
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\ExtName\Domain\Model\Student>
*/
protected $students = NULL;

/**
 * Sets the students
 *
 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\ExtName\Domain\Model\Student> $students
 * @return void
 */
public function setStudents(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $students) {
        $this->students = $students;
}

【问题讨论】:

    标签: typo3 fluid extbase typo3-6.2.x


    【解决方案1】:

    我无法说出原因,为什么你会看到这个异常,但你可以尝试让 PropertyMapper 对这个集合放松一点。

    为此,您需要在同一控制器中使用 initialize[yourAction]() 方法。

    你应该在那儿放这样的东西:

    $this->arguments['appointment']
            ->getPropertyMappingConfiguration()
            ->forProperty('students.*')
            ->allowAllProperties();
    

    这将告诉 PropertyMapper 不要对 'students' 集合属性严格。

    【讨论】:

    • 我不敢相信,它不仅消除了错误,甚至解决了整个问题:D 当我现在点击保存时,数据库中有多个学生 - 谢谢! :) 我不知道在这种情况下你可以使用“*”,好提示!
    猜你喜欢
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多