Doctrine2 ODM - [Semantical Error]
-
25-04-2021 - |
Question
I keep getting this error:
PHP Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "@Document" in class Documents\Translation was never imported.' in /home/bmay/devel/svn/wwv/trunk/test_mongo_record/doctrine-mongodb-odm/lib/vendor/doctrine-mongodb-odm/lib/vendor/doctrine-common/lib/Doctrine/Common/Annotations/AnnotationException.php:52
Code is simple here:
namespace Documents;
/** @Document */
class Translation
{
//private $string;
//private $date;
/** @String */
private $name;
public function setName($name) {
$this->name = $name;
}
}
Solution
The annotation usage changed in the new versions. Before you can use an annotation, Doctrine\ODM\MongoDB\Mapping\Annotations
should be imported with use
:
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/** @ODM\Document */
class Translation
{
/** @ODM\String */
private $name;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow