使用generate.php时出现Doctrine致命错误

发布于 2024-09-10 16:05:20 字数 905 浏览 1 评论 0原文

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

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

generate.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)

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

I'm working on the Doctrine tutorial at http://www.Doctrine-project.org/ and I receive a fatal error when I try to run my generate.php script which makes my models and makes tables in the database:

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

generate.php:

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

and 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)

I am quite stumped by this, I can get it to correctly create other tables that are very similar or much more complicated then this one. I've tried rewriting it as well. I really have no clue where this error is coming from.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹短裙飘 2024-09-17 16:05:20

您需要使用 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'); 

You need to register the models with the autoloader provided by Doctrine. No need to use any Iterators or what so ever

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

You can of course use it sevaral times:

Doctrine::loadModels('path/to/your/models/generated'); 
Doctrine::loadModels('path/to/your/models/custom');    
Doctrine::loadModels('path/to/your/models'); 
紫轩蝶泪 2024-09-17 16:05:20

找到这个:

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

嗨,我偶然发现了同样的情况
问题,我想我知道问题出在哪里
问题是。

所以
Doctrine_Core::createTablesFromModels()
调用 Doctrine_Export::exportSchema()
这又调用
Doctrine_Core::loadModels()。

Doctrine_Core::loadModels() 使用
RecursiveIterator迭代器和迭代
覆盖所有找到的文件。

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

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

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

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

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

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

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

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

Found this:

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

Hi, I've stumbled upon the same
problem and I think I know where the
issue is.

So
Doctrine_Core::createTablesFromModels()
calls Doctrine_Export::exportSchema()
which in turn calls
Doctrine_Core::loadModels().

Doctrine_Core::loadModels() uses
RecursiveIteratorIterator and iterates
over all found files.

Now I think the order of files
returned by RecursiveIteratorIterator
is not always the same (depends on OS,
filenames and cosmic radiation ), but
the most important thing here is that
class files from 'modules/generated'
directory (as in examples) ARE NOT
included before subclasses derived
from generated classes. This means
that Doctrine_Core::autoload() fails
to load classes from
'modules/generated' directory, exactly
this check fails:

if (0 !== stripos($className,
'Doctrine_') ||
class_exists($className, false) ||
interface_exists($className, false))

as base class is not starting with
'Doctrine_' and is not yet loaded.

To fix it properly the algorithm for
loading modules must be changed to
first include 'modules/generated'
classes and then rest of classes. I am
not sure but maybe Core::autoload()
might be changed to include base
classes properly.

QUICK WORKAROUND: As a quick
workaround I've changed parameters in
call to createTablesFromModels() to:

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

as createTablesFromModels() can accept
array of directories.

Hope this helps you, please let me
know if you need any more information.
Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文