我对 Doctrine 2 很陌生,并且正在使用注释来进行数据库映射。我想更进一步并使用一些自定义注释。目的是能够制作表格等,可以通过注释创建设置。我在阅读任何注释时都遇到了问题——即使是 @Table 之类的注释也没有从解析器返回。
我正在使用 Codeigniter 2 和模块化扩展。在我的控制器中,我有:
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setDefaultAnnotationNamespace('MyCompany\Annotations');
$reflClass = new ReflectionClass('models\User');
$classAnnotations = $reader->getClassAnnotations($reflClass);
print_r($classAnnotations);
它返回一个空数组。
然后我的库/注释文件夹中有一个文件,Bar.php:
namespace MyCompany\Annotations;
class Bar extends \Doctrine\Common\Annotations\Annotation
{
public $foo;
}
最后,我的用户模型:
/**
* @Entity
* @Table(name="user")
* @MyCompany\Annotations\Bar(foo="bar")
* @MyCompany\Annotations\Foo(bar="foo")
*/
class User {
}
我正在尝试遵循此示例: http: //www.doctrine-project.org/projects/common/2.0/docs/reference/annotations/en#setup-and-configuration
提前感谢您的帮助!
标记。