【问题标题】:Fatal Error with Doctrine while using generate.php使用 generate.php 时出现致命错误
【发布时间】:2010-07-22 17:45:43
【问题描述】:

我正在http://www.Doctrine-project.org/ 上编写 Doctrine 教程,当我尝试运行生成模型并在数据库中创建表的 generate.php 脚本时收到一个致命错误:

Fatal error: Class 'BaseCharity' not found in ...\models\Charity.php on line 14

生成.php:

require_once('bootstrap.php');
Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::generateModelsFromYaml('schema.yml', 'models');
Doctrine_Core::createTablesFromModels('models');

和 schema.yml

Charity:
  actAs: [Timestampable]
  columns:
    active:
      type: boolean
      default: '1'
    owed: decimal(32,2)
    totalPayed: decimal(32,2)
    name: string(255)
    website: string(255)
    description: text
    icon: string(255)

我对此感到很困惑,我可以让它正确地创建其他非常相似或更复杂的表。我也试过重写它。我真的不知道这个错误是从哪里来的。

【问题讨论】:

    标签: php doctrine yaml


    【解决方案1】:

    您需要使用 Doctrine 提供的自动加载器注册模型。无需使用任何迭代器或其他任何东西

    Doctrine::loadModels('path/to/your/models');  
    

    你当然可以多次使用它:

    Doctrine::loadModels('path/to/your/models/generated'); 
    Doctrine::loadModels('path/to/your/models/custom');    
    Doctrine::loadModels('path/to/your/models'); 
    

    【讨论】:

      【解决方案2】:

      找到这个:

      http://www.doctrine-project.org/jira/browse/DC-344

      嗨,我偶然发现了同样的问题 问题,我想我知道 问题是。

      所以 Doctrine_Core::createTablesFromModels() 调用 Doctrine_Export::exportSchema() 这反过来又调用 Doctrine_Core::loadModels().

      Doctrine_Core::loadModels() 使用 RecursiveIteratorIterator 和迭代 所有找到的文件。

      现在我认为文件的顺序 由 RecursiveIteratorIterator 返回 并不总是相同的(取决于操作系统, 文件名和宇宙辐射),但是 这里最重要的是 来自“模块/生成”的类文件 目录(如示例)不是 包含在派生的子类之前 从生成的类。这表示 Doctrine_Core::autoload() 失败 从加载类 'modules/generated' 目录,确切地说 此检查失败:

      如果 (0 !== stripos($className, '教义_') || class_exists($className, false) || interface_exists($className, false))

      因为基类不是以 'Doctrine_' 尚未加载。

      要正确修复它的算法 加载模块必须更改为 首先包括“模块/生成” 类,然后是其他类。我是 不确定,但可能是 Core::autoload() 可能会更改为包括基础 正确分类。

      快速解决方法:作为快速 解决方法我更改了参数 调用 createTablesFromModels() 到:

      Doctrine_Core::createTablesFromModels(array('models/generated','models'));

      因为 createTablesFromModels() 可以接受 目录数组。

      希望对你有帮助,请让我 知道您是否需要更多信息。 谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-04-22
        • 1970-01-01
        • 1970-01-01
        • 2012-01-27
        • 1970-01-01
        • 1970-01-01
        • 2022-11-09
        相关资源
        最近更新 更多