symfony 5 无法在课堂上读取属性"tipoinvitado"



我需要选择用户并选择一个角色,但是当我添加角色时,我得到这个失败:

无法读取属性" tipoinvitado"在类"AppEntity eventto "

属性"tipoinvitado"有其他实体

控制器

public function a(Request $request, Evento $evento){
$user_repo = $this->getDoctrine()->getRepository(User::class);
$users = $user_repo->findAll();    
$evento = $this->getDoctrine()->getRepository(Evento::class)->findOneById($evento); 
$form = $this->createForm(AsignarEventoFormType::class, $evento);
$form->handleRequest($request);

if($form->isSubmitted() && $form->isValid()){
$users = $evento->GetUsers();
foreach($users as $user){
$formulario = $form->get("tipoinvitado")->getData();
$userhasevento = new UserHasEvento();
$userhasevento->SetTipoinvitado($formulario);
$userhasevento->SetFechainscripcion(new DateTime('now'));
$userhasevento->SetEventoid($evento->getId());
$userhasevento->SetUserid($user->getId());
$em = $this->getDoctrine()->getManager();
$em->persist($userhasevento);
$em->flush();
}
return $this->redirect($this->generateUrl('evento_detalle', ['id' => $evento->getId()]));

}        
return $this->render('evento/AsignarEvento.html.twig',[
'form' => $form->createView()
]);
}

我的形式
use AppEntityUser;
class AsignarEventoFormType extends AbstractType{

public function buildForm(FormBuilderInterface $builder, array $options){
$builder->add('Users', EntityType::class, [
'class' => User::class,
'multiple' => true,
])
->add('tipoinvitado', ChoiceType::class, array(
'label' => 'Prioridad',
'choices' => array(
'VIP' => 'VIP',
'Empresa' => 'Empresa'
)
))
->add('submit', SubmitType::class, array(
'label' => 'Asignar'
));
}

}```

tipoinvitado不是Evento的性质。如果你想添加表单字段,不是表单数据类的属性,只需添加'mapped' => false到您的字段。

->add('tipoinvitado', ChoiceType::class, array(
'label' => 'Prioridad',
'mapped' => false,
'choices' => array(
'VIP' => 'VIP',
'Empresa' => 'Empresa'
)
))

相关内容

  • 没有找到相关文章

最新更新