【问题标题】:Doctrine 2 - problems with "Getting Started XML-Edition" - generating database schemaDoctrine 2 - “Getting Started XML-Edition”的问题 - 生成数据库模式
【发布时间】:2011-04-02 21:00:06
【问题描述】:

之前从未接触过 Doctrine(1 或 2),我关注 this tutorial for Doctrine 2

我正在使用命令行生成数据库模式。这是 cli-config.php 文件,根据教程:

<?php
$cliConfig = new Doctrine\Common\Cli\Configuration();
$cliConfig->setAttribute('em', $entityManager);

当我运行它时,我得到一个错误:

Fatal error: require(): Failed opening required 'Doctrine\Common\Cli\Configuration.php' 

因为 cli-config.php 文件引用的类不存在。我也尝试过清空 cli-config.php 文件,这当然也不起作用 - 说“未定义帮助程序“em”。”

我使用的是 2.0.0BETA3 版本。我知道这是一个测试版,所以他们可以更改一些文件,但我在任何地方都找不到那个类。

关于如何让它工作的任何想法?

【问题讨论】:

    标签: php orm doctrine doctrine-orm


    【解决方案1】:

    XML 入门中的文档在这方面已经过时。请参阅手册中的工具部分了解如何配置 CLI 工具:

    http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html

    所有其余部分仍然按描述工作。我会尽快更新这部分。

    【讨论】:

      【解决方案2】:

      假设您使用 pear

      安装了 Doctrine

      $ sudo pear install pear.doctrine-project.org/doctrineORM

      这将安装三个“Doctrine 2”包:DoctrineCommon、DoctrineDBAL 和 DoctrineORM。在 Ubuntu 上,这些软件包将位于 /usr/share/php/Doctrine 中,而学说命令行实用程序将安装在 /usr/bin 中。

      通过此设置,这是您可以使用的 cli-config.php 版本(注意:DIR 前后应该有两个下划线。出于某种原因,它们没有显示)。

      <?php
      require ‘Doctrine/ORM/Tools/Setup.php’;
      // Setup Autoloader (1)
      Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
      
      require_once 'Doctrine/Common/ClassLoader.php';
      
      $classLoader = new Doctrine\Common\ClassLoader('Entities', __DIR__); 
      
      $classLoader->register();
      
      $classLoader = new Doctrine\Common\ClassLoader('Proxies', __DIR__); 
      
      $classLoader->register();
      
      $config = new \Doctrine\ORM\Configuration();
      
      $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
      
      $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
      
      $config->setMetadataDriverImpl($driverImpl);
      
      $config->setProxyDir(__DIR__ . '/Proxies');
      
      $config->setProxyNamespace('Proxies');
      
      $connectionOptions = array(
              'driver' => 'pdo_mysql',
              'dbname' => 'bugs',
              'user' => 'bugs',
              'password' => 'xyzabc',
        'host' => 'localhost' );
      
      $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
      
      $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
          'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
          'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
      ));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-06
        • 2011-08-19
        • 2022-01-20
        • 1970-01-01
        • 2018-02-06
        • 1970-01-01
        相关资源
        最近更新 更多