学说2.3& 2.4找不到MappingException类

时间:2014-04-22 10:41:41

标签: php doctrine-orm

我无法让Doctrine 2工作,我希望有更好眼睛的人可以指出问题。

我过去曾经广泛使用过1.2版本,这是一件轻而易举的事情,但版本2.3和2.4只是在完全遵循文档并尝试使用不同的驱动程序后才会飞。

我已经在其他地方建议使用了来自控制台的orm:clear-cache功能,并且我没有使用某些用户遇到问题的eAccelerator缓存。

我能够以所有格式创建EM和逆向工程映射,但是当我尝试做任何有用的事情时,我会收到MappingException。

以下内容与以下所有示例相关:

//Paths & Setup
$paths = array(“/home/site/public_html/deployment/Models”);
$proxyDir = “/home/site/public_html/deployment/System/DoctrineProxies”;
$cacheDir = “/home/site/public_html/deployment/System/DoctrineCache”;
$proxyNamespace = 'DoctrineProxies';
$devMode = 1;

// connection
$dbParams = array('driver'   => 'pdo_mysql',
                  'user'     => $this->user,
                  'password' => $this->pass,
                  'dbname'   => $this->dbname,
                  'host'     => $this->host
                  );

首先,我成功地从数据库反向设计了映射,如下所示:

//Configure and create the EM
$config = \Doctrine\ORM\Tools\Setup::createConfiguration($devMode);
$driver = $config->newDefaultAnnotationDriver($paths);      
$cache = new \Doctrine\Common\Cache\ArrayCache;
$config ->setMetadataDriverImpl($driver);
$config ->setQueryCacheImpl($cache);
$config ->setProxyDir($proxyDir);       
$config ->setProxyNamespace($proxyNamespace);
$config->setAutoGenerateProxyClasses(\Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_ALWAYS); 
\Doctrine\ORM\Proxy\Autoloader::register($proxyDir, $proxyNamespace);
$em = \Doctrine\ORM\EntityManager::create($dbParams, $config);

//Load DB Driver
$em->getConfiguration()->setMetadataDriverImpl(
            new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
                $em->getConnection()->getSchemaManager()
            )
        );

//Generate metadata info
$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();

//Export metadata to models
$cme = new \Doctrine\ORM\Tools\ClassMetadataExporter();
$exporter = $cme->getExporter('annotation', $paths[0]);
$exporter->setMetadata($metadata);
$eg = new \Doctrine\ORM\Tools\EntityGenerator;
$exporter->setEntityGenerator(new \Doctrine\ORM\Tools\EntityGenerator);
$exporter->export();
echo “DONE!”;

现在我有2个注释映射,如下所示:

/home/site/public_html/deployment/Models/Node.php /home/site/public_html/deployment/Models/Page.php

节点映射的内容:

use Doctrine\ORM\Mapping as ORM;

/**
 * Node
 *
 * @ORM\Table(name="Node")
 * @ORM\Entity
 */
class Node
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="URL", type="string", length=255, nullable=true)
     */
    private $url;

}

尝试执行检索时收到MappingException,如果使用Yaml驱动程序,结果完全相同:

//Configure and create the EM exactly as above
//…

//Retrieve a node
$node = $em->find(‘Node', 14);

结果:

Fatal error: Uncaught exception 'Doctrine\Common\Persistence\Mapping\MappingException' with message 'Class 'Node' does not exist

命令行工具orm:info产生以下结果:

Found 2 mapped entities:

[Doctrine\Common\Persistence\Mapping\MappingException]  
Class 'Node' does not exist 

orm:info

如果我使用与导出器和Yaml驱动程序进行逆向工程的Yaml映射,我可以使用命令行工具生成带注释的实体(orm:generate-entities --generate-annotations =" 1"所以这让我相信映射是有效的,并且对于教义是可见的,但是当我尝试使用任何映射时,我仍然会收到相同的MappingException。

0 个答案:

没有答案