gpt4 book ai didi

php - 使用 Doctrine 2 Annotation reader 进行自定义注释

转载 作者:行者123 更新时间:2023-12-04 14:42:15 25 4
gpt4 key购买 nike

我是 Doctrine 2 的新手,正在使用注释来进行数据库映射。我想更进一步并使用一些自定义注释。目的是能够制作表单等可以通过注释创建的设置。我在阅读任何注释时遇到问题 - 即使是 @Table 等类注释也没有从解析器返回。

我正在使用 Codeigniter 2 和模块化扩展。在我的 Controller 中,我有:

$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setDefaultAnnotationNamespace('MyCompany\Annotations');
$reflClass = new ReflectionClass('models\User');
$classAnnotations = $reader->getClassAnnotations($reflClass);
print_r($classAnnotations);

返回一个空数组。

然后我的 libraries/annotations 文件夹中有一个文件 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

提前感谢您的帮助!

标记。

最佳答案

使用

Doctrine\Common\Annotations\AnnotationRegistry

AnnotationRegistry::RegisterLoader($universalClassLoader);
AnnotationRegistry::RegisterFile(__DIR__ . ' PATH_TO_DoctrineAnnotations.php ');

关于php - 使用 Doctrine 2 Annotation reader 进行自定义注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6740010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com