I've got a conseiller entity which have a relation with ConseillerRdp entity. The schema is that a conseiller can have one or more RDPs, RDP which are in fact some conseiller too.
When i try to associate a RDP to a conseiller through a form, i've got this error message :
The form's view data is expected to be of type scalar, array or an
instance of \ArrayAccess, but is an instance of class Nurun\Bundle
\RhBundle\Entity\Conseiller. You can avoid this error by setting the
"data_class" option to "Nurun\Bundle\RhBundle\Entity\Conseiller" or by
adding a view transformer that transforms an instance of class
Nurun\Bundle\RhBundle\Entity\Conseiller to scalar, array or an instance
of \ArrayAccess.
My controller code : public function editAction($id, Request $request) {
$em = $this->getDoctrine()->getManager();
// On récupère le client $id
$conseiller = $em->getRepository('NurunRhBundle:Conseiller')->find($id);
$conseillerRdp = new ConseillerRdp();
$conseillerRdp->setConseiller($conseiller);
$today = new \DateTime();
$conseillerRdp->setDateDebut($today);
$form = $this->get('form.factory')->create(new ConseillerRdpType(), $conseillerRdp);
if ($form->handleRequest($request)->isValid()) {
$feuvert = $em->getRepository('NurunRhBundle:ConseillerRdp')->closeAllRdp($id);
if ($feuvert)
{
$em = $this->getDoctrine()->getManager();
$em->persist($conseillerRdp);
$em->flush();
}
$request->getSession()->getFlashBag()->add('notice', 'Affectation de RDP bien enregistrée.');
return $this->redirect($this->generateUrl('nurun_rh_view', array('id' => $conseiller->getId())));
}
return $this->render('NurunRhBundle:ConseillerRdp:edit.html.twig', array(
'form' => $form->createView(),
));
}
My formType code :
class ConseillerRdpType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('conseiller', 'text', array(
'read_only' => true))
->add('rdp', 'entity', array(
'class' => 'NurunRhBundle:Conseiller',
'multiple' => false,
'required' => true))
->add('dateDebut', 'genemu_jquerydate', array('widget' => 'single_text'))
->add('save', 'submit')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Nurun\Bundle\RhBundle\Entity\ConseillerRdp'
));
}
/**
* @return string
*/
public function getName()
{
return 'nurun_bundle_rhbundle_conseillerRdp';
}
}
My relationship code (in conseiller entity) :
/**
* @ORM\OneToMany(targetEntity="Nurun\Bundle\RhBundle\Entity\ConseillerRdp", mappedBy="conseiller", cascade={"remove"})
*/
private $rdps;
I found some other posts whith this error message but in my case i can't understand what happened. Why is told me to set data_class to conseiller whereas i pass it a conseillerRdp entity ? The entity i want to update is a conseillerRdp and not a conseiller...
Please somebody have an idea ??
Aucun commentaire:
Enregistrer un commentaire