【发布时间】:2019-03-20 22:38:17
【问题描述】:
不确定是否可行,但我想将我的 ChoiceType 的两个选项映射为两个不同的 Announcement 字段。
这是我创建的EditAnnouncementType 中的 ChoiceType
->add('audience', ChoiceType::class,
[
'choices' =>
[
'Students: anybody with a student level field populated' => 'students',
'Employees: anybody with an employee ID number' => 'employees'
],
'expanded' => true,
'required' => true,
'multiple' => true
])
这是我希望表单为现有Announcement 实体自动更新的两个字段。
class Announcement
{
/**
* @param bool $employees
*
* @return $this
*/
public function setEmployees(bool $employees)
{
$this->employees = $employees;
return $this;
}
/**
* @param bool $students
*
* @return $this
*/
public function setStudents(bool $students)
{
$this->students = $students;
return $this;
}
}
我使用两个单独的 CheckBoxType 表单来代替,但是我需要要求用户选择 至少一个 选项,这不可能(据我所知)作为两个单独的表格。
【问题讨论】:
标签: php symfony symfony-forms