我在带有参数的存储库中具有功能。无法从FOSUser捆绑控制器-> FormType->存储库传递此参数。
我尝试像本主题一样使用$ option-Pass custom options to a symfony2 form 并传递$ this-> getUser();但这对我不起作用。无法设置或获取此数据。可能我做错了。
存储库中的功能
Get-Help -Name about_Comparison_Operators
RegistrationFormType:
public function getRanksWithYourPrivilages($id = 1) {
$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$ranks = $this->getEntityManager()->getRepository('App:RanksRows')->getRankListWithYourPrivilages($id);
$ranks = implode(",",$ranks);
return $queryBuilder->select('r')
->from(Ranks::class,'r')
->where('r.id IN ('.$ranks.')');
}
RegistrationController:
public function buildForm(FormBuilderInterface $builder, array $options)
{
//var_dump($options);
$builder
->add('email', EmailType::class, array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'options' => array(
'translation_domain' => 'FOSUserBundle',
'attr' => array(
'autocomplete' => 'new-password',
),
),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
))
->add('rank', EntityType::class, array(
'class' => Ranks::class,
'query_builder' => function (EntityRepository $er) {
return $er->getRanksWithYourPrivilages();
},
'choice_label' => 'name',
))
;
}