Annotations Namespace not loaded DoctrineMongoODMModule for Zend Framework 2

I downloaded the MongoODM Doctrine module for zf2. I have a document manager inside my controller, and everything went well until I tried to save the document. Error with this error:

"[Semantic error] The annotations" @Document "in the SdsCore \ Document \ User class have never been imported."

It seems that the failure in this line is DocParser.php if ('\\' !== $name[0] && !$this->classExists($name)) {

It fails because $name = 'Document' , and the imported annotation class is 'Doctrine\ODM\MongoDB\Mapping\Annotations\Doctrine'

Here is my document class:

 namespace SdsCore\Document; /** @Document */ class User { /** * @Id(strategy="UUID") */ private $id; /** * @Field(type="string") */ private $name; /** * @Field(type="string") */ private $firstname; public function get($property) { $method = 'get'.ucfirst($property); if (method_exists($this, $method)) { return $this->$method(); } else { $propertyName = $property; return $this->$propertyName; } } public function set($property, $value) { $method = 'set'.ucfirst($property); if (method_exists($this, $method)) { $this->$method($value); } else { $propertyName = $property; $this->$propertyName = $value; } } 

}

Here is my action controller:

 public function indexAction() { $dm = $this->documentManager; $user = new User(); $user->set('name', 'testname'); $user->set('firstname', 'testfirstname'); $dm->persist($user); $dm->flush; return new ViewModel(); } 
+3
source share
1 answer

I have not worked on DoctrineMongoODMModule yet, but I will get to it next week. In any case, you are still using the "old way" of loading annotations. Most doctrine projects now use Doctrine\Common\Annotations\AnnotationReader , and your @AnnotationName tells me that you used Doctrine\Common\Annotations\SimpeAnnotationReader . For more information, see the Doctrine \ Common documentation.

So how to fix your document:

 <?php namespace SdsCore\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\Document */ class User { /** * @ODM\Id(strategy="UUID") */ private $id; /** * @ODM\Field(type="string") */ private $name; /** * @ODM\Field(type="string") */ private $firstname; /* etc */ } 
+4
source

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


All Articles