Hello. I have the following question - is it possible to use the use namespace for annotations in Symfony 2?

Example

 namespace classes; use OtherClass\Photo; class Place { /** * @ORM\OneToMany(targetEntity="Photo") // OtherClass\Photo; */ private $photo; } 

Does not work.

Writes that

 The target-entity classes\Photo cannot be found in .... 

What am I doing wrong?

  • 3
    If you refer to the doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/ ... documentation, it says that you can only use namespaces if both the targetEntity and your Place Entity are in the same namespace. Accordingly, an attempt to bind an entity from another namespace via use will cause an error - S. Pronin

1 answer 1

In these annotations you should use the full names of entity classes, since

  • it is universal
  • never mess with another class
    • refactoring will make it easier for you to look for such classes.