Doctrine orm 从未导入自定义批注
我创建了一个条令注释Doctrine orm 从未导入自定义批注,doctrine-orm,symfony,Doctrine Orm,Symfony,我创建了一个条令注释 namespace Fondative\GenBundle\Front\Annotation; use Doctrine\Common\Annotations\Annotation; /** * @Annotation * @Target("PROPERTY") */ class ReferenceAnnotation extends Annotation { } use Fondative\GenBundle\Front\Annotation\ReferenceAn
namespace Fondative\GenBundle\Front\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* @Annotation
* @Target("PROPERTY")
*/
class ReferenceAnnotation extends Annotation {
}
use Fondative\GenBundle\Front\Annotation\ReferenceAnnotation ;
/**
* A Driver.
*
*
*
* @ORM\Entity
*
*/
class Driver {
/*
* @Reference
*/
private $name;
我得到这个例外
[语义错误]属性中的批注“@Reference”
Fondative\TestBundle\Entity\Driver::$name从未导入
或者将注释类重命名为Reference和
use Fondative\GenBundle\Front\Annotation\Reference as Reference ;
/*
* @Reference
*/
private $name;
一个非常常见的错误;)
程序包Doctrine/Annotation
从注释中读取注释ReflectionProperty::getDocComment()
问题示例:
class MyClassA
{
/**
* Foo
*/
private $foo;
/*
* Bar
*/
private $bar;
}
$ref = new \ReflectionClass('MyClassA');
print sprintf(
"Comment of MyClassA::foo -> \n%s\n\n",
$ref->getProperty('foo')->getDocComment()
);
print sprintf(
"Comment of MyClassA::bar -> \n%s\n\n",
$ref->getProperty('bar')->getDocComment()
);
属性foo
有文档注释,但属性bar
没有注释,因为declare comment中存在打字错误(一个特殊字符*
)
在PHP中,文档注释必须从两个字符开始*
修复此打字错误,以及所有作品;) 尝试使用以下use语句:
使用Fondative\GenBundle\Front\Annotation\ReferenceAnnotation作为引用代码>我调用了错误的注释名称:
class MyClassA
{
/**
* Foo
*/
private $foo;
/*
* Bar
*/
private $bar;
}
$ref = new \ReflectionClass('MyClassA');
print sprintf(
"Comment of MyClassA::foo -> \n%s\n\n",
$ref->getProperty('foo')->getDocComment()
);
print sprintf(
"Comment of MyClassA::bar -> \n%s\n\n",
$ref->getProperty('bar')->getDocComment()
);