2012-01-20 59 views
0

实体symfony的2另一个项目中使用的实体从Symfony2中有前面有@ORM \主义标签(例如@ORM \实体)。我怎么能只使用doctrine2

当使用教义作为组分,预计标签而不ORM(例如@Entity)。

如果我想在使用的学说,但没有symfony的这会导致问题的另一个项目中使用这些实体从symfony项目。

我怎么可以设置非symfony项目中使用这些类与@ORM \标签?

+0

你打算使用比symfony的不同一个框架?如果是的话,哪一个? – jere

+0

是的......但它是一个传统的定制框架。 – YakobeYak

+0

嗯..我觉得只要你有自动加载类的方式,你可以让它工作...在PHP中使用新的命名空间,你可以把教义库在你的框架的“LIB”文件夹,自动加载它,然后从你的实体,你可以做一些像'使用\ YourLibs \ Doctrine \ ORM作为ORM',所以你不必在你的实体中改变任何事......虽然不太确定... – jere

回答

0

目前我已经为我的意见周围由MadManMonty建议的工作问题:

你有使用不同的映射方法,例如考虑作为yaml或xml来管理而不是注释,因为它可能提供了一种简单的替代方法来解决该问题? - MadManMonty

0

@ORM\前缀不Symfony的具体。它在Doctrine通用文档中:http://www.doctrine-project.org/docs/common/2.2/en/reference/annotations.html#introduction

您必须按文档中所述注册您使用AnnotationRegistry::registerFile()的注释文件。另外,检查Symfony的app/autoload.php文件。它注册了自动加载磁带机:在AnnotationRegistry

AnnotationRegistry::registerLoader(function($class) use ($loader) { 
    $loader->loadClass($class); 
    return class_exists($class, false); 
}); 
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); 
0

我得到它的工作像这样通过EntityManager的$ useSimpleAnnotationReader设置为false ::创建():

// bootstrap.php 
require_once "vendor/autoload.php"; 

use Doctrine\ORM\Tools\Setup; 
use Doctrine\ORM\EntityManager; 
use Doctrine\Common\Annotations\AnnotationRegistry; 

//IGNORE IF YOU DONT NEED SERIALIZER/VALIDATOR 
AnnotationRegistry::registerAutoloadNamespace('JMS\Serializer\Annotation', $vendorPath . '/jms/serializer/src'); 
AnnotationRegistry::registerAutoloadNamespace('Symfony\Component\Validator\Constraint', $vendorPath . '/symfony/validator'); 
//IGNORE IF YOU DONT NEED SERIALIZER/VALIDATOR 

AnnotationRegistry::registerFile($vendorPath . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); 

$paths = array("/path/to/entities-or-mapping-files"); 
$isDevMode = false; 

// the connection configuration 
$dbParams = array(
    'driver' => 'pdo_mysql', 
    'user'  => 'root', 
    'password' => '', 
    'dbname' => 'foo', 
); 

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); 
//LAST PARAMETER SETS $useSimpleAnnotationReader TO FALSE 
$entityManager = EntityManager::create($dbParams, $config, null, null, false);