In a controller, I create a form:
$em = $this->getDoctrine()->getManager();
$formProjetSearch = $this->createForm(EgwProjetSearchType::class, $em, [
'em' => $this->getDoctrine()->getManager(),
]);
In my EgwProjetSearchType, I have:
$builder->add('dispositif', 'entity', array(
'class' => 'LeaPrestaBundle:EgwDispositif',
'property' => 'nomDispositif',
'label' => 'nomDispositif',
'required' => true,
'empty_value' => '',
'query_builder' => function(EntityRepository $er)
{
return $er->createQueryBuilder('d')
->where('d.isActive = :isActive')
->setParameter('isActive', 1)
->orderBy('d.nomDispositif','ASC');
},
));
And I've got this error:
Neither the property "dispositif" nor one of the methods "getDispositif()", "dispositif()", "isDispositif()", "hasDispositif()", "__get()" exist and have public access in class "Doctrine\ORM\EntityManager".
Nonetheless, the entity exists:
<?php
namespace Lea\PrestaBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Lea\PrestaBundle\Entity\EgwDispositif
*
* @ORM\Table(name="egw_dispositif")
* @ORM\Entity
*/
class EgwDispositif
{
/**
* @var integer $idDispositif
*
* @ORM\Column(name="id_dispositif", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $idDispositif;
/**
* @ORM\ManyToOne(targetEntity="EgwTypePrestation", inversedBy="dispositifs")
* @ORM\JoinColumn(name="id_type_prestation", referencedColumnName="id")
*/
private $idTypePrestation;
ETC ...
Thanks for your help !
Thakns for your messages, but, I just want to display in a form a entity in a listbox : i use the type EgwProjetSearchType, i add a field which is "dispositif" coming from entity EgwDispositif (which exists) and the return message is :
Neither the property "dispositif" nor one of the methods
"getDispositif()", "dispositif()", "isDispositif()", "hasDispositif()",
"__get()" exis``t and have public access in class
"Doctrine\ORM\EntityManager"
So it's not a problem of argument EM passed in the form EgwProjetSearchType : Symfony says "the entity doesnt exists"....
I dont have to pass EwgDispositif ?? It was not the cas in Symfony 2 : i had :
$formProjetSearch = $this->createForm(new EgwProjetSearchType($this-
getDoctrine()->getManager()));
And this doesnt work anymore in 3.4. So i changed the code :
$formProjetSearch = $this->createForm(EgwProjetSearchType::class, $em, [
'em' => $this->getDoctrine()->getManager(),
]);
createForm
expects the data to be handled (e.g. your entity [though beware best practices]), you're passing the entity manager, which is probably not what you want. – Yoshi'em' => $this->getDoctrine()->getManager(),
. – Yoshi$em
as the second parameter tocreateForm
. As per your code$em
is the entity manager which obviously is not the form data! What you need is (for example), something like:$this->createForm(EgwProjetSearchType::class, new EgwDispositif(), [ 'em' => $this->getDoctrine()->getManager(), ]);
– Yoshi