Ian*_*ips 2 php doctrine annotations symfony
我正在将一个旧的PHP项目转换为Symfony2框架.有些页面现在由我的Symfony2前端控制器(index.php)处理,但许多页面尚未转换.
问题是,在Symfony中,我的所有Doctrine实体注释都必须以ORM \前缀开头,但在Symfony之外,该前缀似乎没有启用,因此我收到以下错误:
Class MyProject\MyBundle\Entity\MyClass is not a valid entity or mapped super class.
我试图复制Symfony所做的任何设置,包括遵循这些说明 [doctrine-project.org],并实际上将app/autoload.php完全包含在我的遗留引导过程中.但没有任何作用.
有谁知道如何手动复制Symfony为我的Doctrine注释启用ORM \前缀的任何内容?
我从Symfony2 Google小组得到了答案.问题是文档中显示的Doctrine配置在SimpleAnnotationReader幕后使用,但您需要定期AnnotationReader使用ORM\命名空间前缀.我通过替换它来实现它:
$config = new Doctrine\ORM\Configuration();
$driver = $config->newDefaultAnnotationDriver('/path/to/my/entities');
有了这个:
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
// ...
$config = new Doctrine\ORM\Configuration();
$reader = new AnnotationReader();
$driver = new AnnotationDriver($reader, '/path/to/my/entities');
| 归档时间: | 
 | 
| 查看次数: | 1689 次 | 
| 最近记录: |