【发布时间】:2016-04-21 13:10:00
【问题描述】:
我在 Symfony2 中有以下模型,因为关系具有额外的属性(布尔值),因此也必须表示为实体。
我现在正在制作表格,以标记参加过的各种候选人(父母)的培训完成。
我使用的嵌套形式如下:
class TrainingCompletionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('titre', 'text', array('disabled' => 'true'))
->add('Intervenant', 'collection', array(
'type' => new TrainingCandidatesType(),'label'=>'Candidat(s)'
,'options' => array('label'=>' '))
);
}
这是TrainingCandidatesType表格
class TrainingCandidatesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('parents','entity',array('class'=>'ParentsBundle:Parents'
,'label'=>' ','disabled'=>true))
->add('completed')
;
}
这可行(父母的提交检查了已完成),但是它会导致树枝将每个父母呈现为一个下拉列表,其中每个父母都作为一个值,如下所示。我已经禁用了下拉菜单,因为没有让用户从列表中进行选择。候选人的名字不是可以选择的。
有没有办法在 Symfony 中将每个父名称显示为标签或禁用文本输入,而无需参考数据转换器或事件订阅者?
我在 Stack 网站上查看了相关问题,但没有找到与此问题非常相似的问题。
有没有更好的方法让我愿意尝试?还是我从磨损的角度接近它?
【问题讨论】: