我想将一些自定义选项从类“AffaireType”传递给我的类“PointageType”,例如当前用户的 id 以在我的类“PointageType”中创建查询。
我试图在 AffaireType 的 buildForm() 函数的 'entry_options' 中传递我的用户 ID,但它显示了一个错误:
选项“id”不存在。定义的选项有:“action”、“allow_extra_fields”、“allow_file_upload”、“attr”、“attr_translation_parameters”、“auto_initialize”、“block_name”、“block_prefix”、“by_reference”、“compound”、“constraints”、“csrf_field_name "、"csrf_message"、"csrf_protection"、"csrf_token_id"、"csrf_token_manager"、"data"、"data_class"、"disabled"、"empty_data"、"error_bubbling"、"error_mapping"、"extra_fields_message"、"help"、 “help_attr”、“help_html”、“help_translation_parameters”、“inherit_data”、“invalid_message”、“
我的 AffaireType 类:
class AffaireType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('numAffaire');
$builder->add('descAffaire');
$builder->add('pointages', CollectionType::class, [
'entry_type' => PointageType::class,
'entry_options' => array(
'id' => 8,
),
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Affaires::class,
]);
}
}
我的 PointageType 类:
class PointageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('heurePointage');
//I want to do the query here
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Pointage::class,
]);
}
}
我认为这段代码在 Symfony 2/3 中有效,但我如何用 Symfony 4.3 做到这一点?
PIPIONE