【发布时间】:2017-11-23 13:58:41
【问题描述】:
我有一组嵌入在 formType 中的表单。
class RateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder ->add('rate')
->add('options', CollectionType::class, array(
'entry_type' => RatesHasOptionsType::class,
'entry_options' => array('label' => __?????_____ ))
)
->add('save', SubmitType::class, array('label' => 'create'));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Rates::class,
));
}
}
嵌入的表单是
$builder->add('price', MoneyType::class, array(
'currency' => 'CHF',
));
它来自多对多关系:多速率可以有多个选项
rates_has_options:
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| rate_id | int(11) | YES | MUL | NULL | |
| option_id | int(11) | YES | MUL | NULL | |
| price | double | NO | | NULL | |
+-----------+---------+------+-----+---------+----------------+
我怎样才能让我的选项标签带有选项名称? 到目前为止,它给了我 0、1、2、3,我认为这是选项数组的关键。
【问题讨论】:
-
这适用于“choice_label”,但看起来不适用于“label”。是吗?
标签: symfony symfony-forms