在我自己的自定义类中使用 Propel ORM
我正在将我之前编写的一些类重构到我的 Symfony 项目中(带有 Propel ORM 的 v1.3.2)。
这些类最初使用直接连接到数据库,我想重构这些类(存储在 $(SF_LIB_DIR) 中),以便我可以调用 propel 并使用 ORM 对象。
为了澄清,例如,我希望能够在我的自定义类中使用这样的代码:
try {
$con = Propel::getConnection();
$c = new Criteria();
$foo = new PropelORMFooObject();
$foobar = PropelORMFooBarObjectPeer::fetch($c);
//set fields etc
$foo->setFooBar($foobar);
// now save using obtained connection ..
$foo->save($con)
}catch(SomeException $e)
{
//deal with it
}
我假设我需要向我的自定义库添加一些 require_once() 语句,但不清楚要包含哪些文件。有谁知道该怎么做?
I am refactoring a few classes I wrote a while ago, into my Symfony project (v1.3.2 with Propel ORM).
The classes originally used direct connections to the database, I want to refactor those classes (stored in $(SF_LIB_DIR)) so that I can call propel and also use the ORM objects.
To clarify, So for example, I want to be able to use code like this in my custom classes:
try {
$con = Propel::getConnection();
$c = new Criteria();
$foo = new PropelORMFooObject();
$foobar = PropelORMFooBarObjectPeer::fetch($c);
//set fields etc
$foo->setFooBar($foobar);
// now save using obtained connection ..
$foo->save($con)
}catch(SomeException $e)
{
//deal with it
}
I assume that I will need to add some require_once() statements to my custom libraries, but it is not clear which files to include. Does anyone know how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你在说什么。只要您从 symfony 应用程序中执行此代码,Propel 类就会被自动加载器带入执行上下文。
您真的收到“类未定义”错误吗?
I'm not sure what you're getting at. As long as your executing this code from within a symfony application, the Propel classes will be brought into the execution context by the autoloader.
Are you actually getting "class not defined" errors?