自升级到TYPO3 6.2 extbase以来,多选不起作用

时间:2016-10-24 18:56:31

标签: typo3 fluid extbase typo3-6.2.x

我刚检查过,在我的工作版本中使用TYPO3 4.7的情况下html输出似乎与此相同 我预约可以有多个学生。我通过自动完成textinput-field将它们添加到多选中。

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

1 个答案:

答案 0 :(得分:2)

我无法说明原因,为什么会看到此异常,但您可以尝试让PropertyMapper对此集合略微放松。

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

你应该放这样的东西:

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

这将告诉PropertyMapper不要严格对待学生&#39;收集财产。

相关问题