自定义注释从未进口
问题描述:
我创建了一个学说注释自定义注释从未进口
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 \实体\驱动程序:: $名称从未导入。
答
class Driver {
/*
* @ReferenceAnnotation
*/
private $name;
或重命名的注释类与参考和
use Fondative\GenBundle\Front\Annotation\Reference as Reference ;
/*
* @Reference
*/
private $name;
答
一个非常常见的错误;)
封装Doctrine/Annotation
从评论viaReflectionProperty::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
没有评论,因为在申报评论(一个特殊字符*
)存在拼写错误。
在PHP文档评论必须从两个字符*
开始!
修复此错字,和所有的工作;)
尝试用这种使用语句:'使用Fondative \ GenBundle \接待\注释\ ReferenceAnnotation作为参考;' – Matteo
我打电话了错误的注释名称: –