Propel 1.5.6 的自动加载器似乎无法完全工作
我已在 Mac 上安装了 Propel 1.5.6,通过 MacPorts 运行 PHP 5.12.14。我已经创建了一个模式,生成了一个模型,运行了 sql 生成和插入任务,现在正在转向运行时内容。
我有以下代码可以正常工作(它创建一行,然后计算行数):
<?php
// Set up some paths & schema info
$projectPath = realpath( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' );
$schemaName = 'database';
$modelPath = $projectPath . "/${schemaName}/build/classes";
// Init propel
require_once $projectPath . '/lib/propel-1.5/runtime/lib/Propel.php';
Propel::init($projectPath . "/${schemaName}/build/conf/${schemaName}-conf.php");
// Add the generated 'classes' directory to the include path
set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
// This seems to be sufficient to get the autoloader working ***
require_once $modelPath . '/database/NodePeer.php';
$node = new Node();
$node->setName('My Node');
$node->setHash(sha1($node->getName()));
$node->save();
$nodes = NodePeer::doSelect(new Criteria());
echo 'Node count: ' . count($nodes) . "\n";
?>
但是,如果我删除带有星号注释的行,我希望它仍然可以工作 - 我认为自动加载器应该启动并为我加载所有必要的模型类。但是,我得到这个:
致命错误:未定义的类常量 “姓名”在 (项目)/database/build/classes/database/om/BaseNode.php 在第 211 行
我破解了自动加载器以回显它加载的类,并发现它确实加载了一些类:
自动加载:节点
自动加载:BaseNode
但是,当加载 BaseNode 时,它会在对 Peer 类的静态引用上遇到困难。我发现如果手动需要 BaseNode 也是如此。
- PHP 是否在我的配置上苦苦挣扎以自动加载静态调用的方法/常量?
- 或者 Propel 自动加载器加载内容的顺序是否存在问题?
目前,我将继续保持原样——将同行纳入进来并不是什么大问题——但我想知道如果没有它我是否可以逃脱。少了一件需要考虑的事情!
I have installed Propel 1.5.6 onto my Mac, running PHP 5.12.14 via MacPorts. I've created a schema, generated a model, run the sql generation and insertion tasks, and am moving onto the runtime stuff now.
I've got the following code to work fine (it creates a row and then counts the number of rows):
<?php
// Set up some paths & schema info
$projectPath = realpath( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' );
$schemaName = 'database';
$modelPath = $projectPath . "/${schemaName}/build/classes";
// Init propel
require_once $projectPath . '/lib/propel-1.5/runtime/lib/Propel.php';
Propel::init($projectPath . "/${schemaName}/build/conf/${schemaName}-conf.php");
// Add the generated 'classes' directory to the include path
set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
// This seems to be sufficient to get the autoloader working ***
require_once $modelPath . '/database/NodePeer.php';
$node = new Node();
$node->setName('My Node');
$node->setHash(sha1($node->getName()));
$node->save();
$nodes = NodePeer::doSelect(new Criteria());
echo 'Node count: ' . count($nodes) . "\n";
?>
However, if I remove the line with the starred comment, I would expect it still to work - I think the autoloader should kick in and load all the necessary model classes for me. However, I get this:
Fatal error: Undefined class constant
'NAME' in
(project)/database/build/classes/database/om/BaseNode.php
on line 211
I've hacked the autoloader to echo the classes it loads, and found that it does indeed load some classes:
Autoload: Node
Autoload: BaseNode
However, when it loads BaseNode, it struggles on a static reference to the Peer class. I find that this is the case if BaseNode is manually required as well.
- Is PHP struggling on my configuration to autoload statically called methods/constants?
- Or could there be a problem to do with the order in which the Propel autoloader loads things?
For the time being, I'll carry on as I am - it is no major issue to include the peer - but I'd like to know if I can get away without it. One less thing to think about!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,自动加载器不起作用,因为我的模型生成了一个与 Propel 核心提供的接口冲突的类。重命名它会起作用,就像使用命名空间系统一样(当然后者依赖于使用 PHP 5.3.+)。
The autoloader wasn't working in this case because my model generated a class that clashed with an interface provided by the Propel core. Renaming this would have worked, as would using the namespace system (though of course the latter is dependent on using PHP 5.3.+).