Symfony2: database and object settings: neither property ... nor method ... nor method ... exists in the class

I have a Symfony2 project related to a database. For each table, I have an entity.

Now I'm trying to connect one Entity to another using ManyToOne.

Here is the problem:

I have two entities: user and workstation.

In User Entity, I have:

/** * @ORM\ManyToOne(targetEntity="Workplace") * @ORM\JoinColumn(name="workplace", referencedColumnName="place") **/ protected $workplace; /** * Set workplace * * @param integer $workplace */ public function setWorkplace($workplace) { $this->workplace = $workplace; } /** * Get workplace * * @return integer */ public function getWorkplace() { return $this->workplace; } 

In the Workplace object, I:

 /** * @ORM\Column(type="text") */ protected $place; /** * Set place * * @param text $place */ public function setPlace($place) { $this->place = $place; } /** * Get place * * @return text */ public function getPlace() { return $this->place; } 

And with this, I get an exception:

 Neither property "workplace" nor method "getWorkplace()" nor method "isWorkplace()" exists in class "SciForum\Version2Bundle\Entity\Workplace" 

How can this be solved. Thank you very much.

+4
source share
2 answers

try it

 ->add('place','entity', array('class'=>'yourBundle:WorkPlace', 'property'=>'place')) 

in your form Type.

+6
source

@Asish AP is right, but there is no explanation.

In formBuilder, and if you have a relationship between two objects, you must specify the correct object in your form type.

 ->add( 'place', 'entity', array( 'class'=>'yourBundle:WorkPlace', //Link your entity 'property'=>'place' //Specify the property name in the entity )) 

If you specify in formBuilder a property that does not exist, you will get this error:

 Neither property "workplace" nor method "getWorkplace()" nor method "isWorkplace()" exists in class "SciForum\Version2Bundle\Entity\Workplace" 

This is the cause of your error and explanation of the solution.

https://creativcoders.wordpress.com/2014/06/02/sf2-neither-the-property-nor-one-of-the-methods-exist-and-have-public-access-in-class/

+5
source

Source: https://habr.com/ru/post/1439309/


All Articles