English 中文(简体)
推进1.5.6的自动加载器似乎无法完全工作
原标题:Autoloader for Propel 1.5.6 doesn t seem to fully work

我已经在我的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) . "
";
?>

然而,如果我删除带有星号注释的行,我希望它仍然有效-我认为自动加载器应该启动并加载所有必要的模型类。然而,我得到了这个:

Fatal error: Undefined class constant NAME in (project)/database/build/classes/database/om/BaseNode.php on line 211

我已经破解了自动加载器来回显它加载的类,并发现它确实加载了一些类:

自动加载:节点

自动加载:基本节点

然而,当它加载BaseNode时,它会在对Peer类的静态引用上遇到困难。我发现,如果BaseNode也是手动需要的,那么情况就是这样。

  • 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?

就目前而言,我会继续我的现状——包括同龄人并不是什么大问题——但我想知道如果没有它我是否能逃脱惩罚。少想一件事!

最佳回答

在这种情况下,自动加载器无法工作,因为我的模型生成了一个与Propel核心提供的接口冲突的类。重命名它会起作用,就像使用名称空间系统一样(当然后者依赖于使用PHP5.3.+)。

问题回答

暂无回答




相关问题
Saving and retrieving blobs using Propel ORM

I am using Propel (1.4) with Symfony 1.31 (with mySQL db). I want to save save/retriev BLOB (gzipped) data to/from the database My db schema is defined in YML. Suppose the schema looks like this: ...

symfony setPostValidator with sfValidatorFile

I am going through an issue to setup a file upload validator on callback. I want to achieve this: I have a form, where user choose the type of the file they are uploading and upload the file. So I ...

Doctrine to Propel snippet

I am using the Propel ORM with SF (1.4). I am writing a class, and I need to rewrite a query Doctrine query into Propel: $q = Doctrine_Core::getTable( sfGuardRememberKey )->createQuery( r ) ...

Propel Single Table Inheritance Issue

I have a table called "talk", which is defined as abstract in my schema.xml file. It generates 4 objects (1 per classkey): Comment, Rating, Review, Checkin It also generates TalkPeer, but I couldn t ...

Propel ORM including MAX in criteria

I am writing a query using the Propel ORM The query is of the form: select * from some_table where some_table.created_at = (SELECT MAX(some_table.created_at) from some_table); I got this far: $c =...

How do I setup Symfony to create multiple database schemas?

In my project I have 2 databases. propel-build-model is already set up to work for 2 databases - Multiple databases support in Symfony If I make changes to either of the databases, I need the propel-...

热门标签