PHP ORM:Doctrine 与 Propel

发布于 2024-08-18 12:24:04 字数 1700 浏览 4 评论 0原文

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

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

发布评论

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

评论(10

﹏半生如梦愿梦如真 2024-08-25 12:24:04

我会选择教义。在我看来,这是一个更加活跃的项目,并且作为 symfony 的默认 ORM,它得到了更好的支持(尽管官方认为 ORM 是平等的)。

此外,我更喜欢您处理查询的方式(DQL 而不是 Criteria):(

<?php
// Propel
$c = new Criteria();
$c->add(ExamplePeer::ID, 20);
$items = ExamplePeer::doSelectJoinFoobar($c);

// Doctrine
$items = Doctrine_Query::create()
       ->from('Example e')
       ->leftJoin('e.Foobar')
       ->where('e.id = ?', 20)
       ->execute();
?>

Doctrine 的实现对我来说更加直观)。

另外,我真的很喜欢你在《教义》中处理关系的方式。

我认为 Doctrine 文档中的这一页值得一读: http://www.doctrine-project.org/documentation/manual/1_2/en/introduction:doctrine-explained

总结一下:如果我要开始一个新项目或者必须在学习 Doctrine 和 Propel I 之间做出选择任何一天都会去学教义。

I'd go with Doctrine. It seems to me that it is a much more active project and being the default ORM for symfony it is better supported (even though officially the ORMs are considered equal).

Furthermore I better like the way you work with queries (DQL instead of Criteria):

<?php
// Propel
$c = new Criteria();
$c->add(ExamplePeer::ID, 20);
$items = ExamplePeer::doSelectJoinFoobar($c);

// Doctrine
$items = Doctrine_Query::create()
       ->from('Example e')
       ->leftJoin('e.Foobar')
       ->where('e.id = ?', 20)
       ->execute();
?>

(Doctrine's implementation is much more intuitive to me).

Also, I really prefer the way you manage relations in Doctrine.

I think this page from the Doctrine documentation is worth a read: http://www.doctrine-project.org/documentation/manual/1_2/en/introduction:doctrine-explained

To sum up: If I were starting a new project or had to choose between learning Doctrine and Propel I'd go for Doctrine any day.

沦落红尘 2024-08-25 12:24:04

我有偏见,因为我对 Propel 的下一个版本提供了一些帮助,但你必须考虑到 Propel 确实是第一个可用的 ORM,然后在 Doctrine 创建时落后了一点,但现在又开始积极开发了。 Symfony 1.3/1.4 附带 Propel 1.4,大多数比较都停留在 Propel 1.3。此外,Propel (1.5) 的下一个版本将包含很多改进,特别是在创建标准方面(导致您需要编写的代码更少)。

我喜欢 Propel,因为它似乎没有 Doctrine 复杂:大多数代码都在少数生成的类中,而 Doctrine 将功能拆分为许多类。我喜欢对我正在使用的库有一个很好的了解(没有太多的“魔法”),但是当然,我对 Propel 有更多的经验,所以也许 Doctrine 在幕后并没有那么复杂。有人说 Propel 更快,但您应该亲自检查这一点,并考虑这是否比其他差异更重要。

也许您还应该考虑 Symfony 插件对于不同框架的可用性。我相信 Propel 在这方面有优势,但我不知道列出的插件中有多少仍然与最新版本的 Symfony 保持同步。

I am biased, since I help a little bit on the next release of Propel, but you must consider that Propel was indeed the first ORM available, then lagged a bit when Doctrine got created, but now has active development again. Symfony 1.3/1.4 comes with Propel 1.4, where most comparisons stop at Propel 1.3. Also, the next release of Propel (1.5) will contain a lot of improvements, especially in the creation of you Criteria (resulting in less code for you to write).

I like Propel because it seems to be less complex than Doctrine: most code is in the few generated classes, whereas Doctrine has split up the functionality in lots of classes. I like to have a good understanding of the libraries I am using (not too much "magic"), but of course, I have more experience with Propel, so maybe Doctrine is not so complicated behind the scenes. Some say Propel is faster, but you should check this for yourself, and consider whether this outweighs other differences.

Maybe you should also consider the availability of Symfony plugins for the different frameworks. I believe Propel has an advantage here, but I don't know how many of the listed plugins are still up-to-date with the latest version of Symfony.

等风来 2024-08-25 12:24:04

这取决于个人喜好。
我使用 Propel 是因为(除其他外)我喜欢这样一个事实:一切都有自己具体的 getter 和 getter。设置器方法。在教义中,情况并非如此。

推进:

$person->setName('Derek');
echo $person->getName();

教义:

$person->name = 'Derek';
echo $person->name;

我喜欢吸气剂和吸气剂的原因setter 的优点是,如果需要的话,我可以将各种逻辑放入其中。但这只是我个人的喜好。

我还应该补充一点,虽然 Propel 过去进展缓慢,但现在又开始积极开发了。在过去的几个月里,它发布了多个新版本。 Propel 的最新版本包含类似于 Doctrine 的“流畅查询界面”,因此如果您不想,则不必再使用 Criteria。

It comes down to personal preference.
I use Propel because (among other things) I like the fact that everything has its own concrete getter & setter method. In Doctrine, this is not the case.

Propel:

$person->setName('Derek');
echo $person->getName();

Doctrine:

$person->name = 'Derek';
echo $person->name;

The reason I like having getters & setters is that I can put all kinds of logic in them, if I need to. But that's just my personal preference.

I should also add that although Propel was slow-moving in the past, it is now under active development again. It has released several new versions in the past few months. The most recent version of Propel includes a "fluent query interface" similar to Doctrine's, so you don't have to use Criteria anymore if you don't want to.

狼性发作 2024-08-25 12:24:04

值得注意的是Doctrine 2目前正在开发中 已发布 [ed] 和功能与 Doctrine 1 当前的稳定版本几乎完全不同。它依赖于 Data Mapper 模式而不是 Active Record,并使用“实体管理器”来处理持久性逻辑。当发布时,它将与 Java 的 Hibernate 更加相似(Doctrine 1 更像 Rails 的 ActiveRecord)。

我一直在开发 Doctrine 2 的 alpha 版本,并且必须说它远远高于 Doctrine 1(只是我的意见,我从未使用过 Propel)。当它发布时,Doctrine 社区很可能会朝着它迈进。

我鼓励您查看 Doctrine,但如果您更喜欢 Propel 和 Doctrine 现在使用的 Active Record 风格,您可能只想坚持使用 Propel。

It should be noted Doctrine 2 is currently in development released [ed] and functions almost completely different from the current stable version of Doctrine 1. It relies on the Data Mapper pattern instead of Active Record, and uses an 'entity manager' to handle persistence logic. When released it will bear closer resemblance to Java's Hibernate (Doctrine 1 is more like Rails' ActiveRecord).

I've been developing with the alpha release of Doctrine 2, and must say it is heads and shoulders above Doctrine 1 (just my opinion, and I've never used Propel). Chances are good that the Doctrine community will move toward it when it's released.

I would encourage you to check out Doctrine, but if you prefer the Active Record style that Propel and Doctrine use now, you might want to just stick with Propel.

魄砕の薆 2024-08-25 12:24:04

这两个参考资料有些过时,所以您仍然涵盖了一些一般性,基本上您必须评估您对框架的体验,原则的一个主要缺点是无法拥有一个 IDE 来让您在该推进器中自动编码获胜者,学习曲线推进和学说非常不同,如果您的项目需要管理复杂的数据模型使用学说,如果您想快速使用记录最好的 ORM 并在 Propel 中找到更多支持,那么推进会更容易互联网的使用,已经比较成熟了,我相信用的最多。

http://propel.posterous.com/propel-141-is-out

The two references are somewhat outdated so you nevertheless cover some generalities, basically you'd have to evaluate your experience with the framework as such, a major drawback to doctrine is the inability to have an IDE that lets you auto-code in that propel is a winner, learning curves propel and doctrine are very different, it is easier to propel, if your project will need to manage complex data model uses doctrine, if you want to work quickly with an ORM which is best documented and find more support in Propel Internet uses, is much more mature and I believe that most used.

http://propel.posterous.com/propel-141-is-out

︶ ̄淡然 2024-08-25 12:24:04

我建议使用 propel 1.6,它更适合 IDE 的自动完成功能。

I'd suggest to use propel 1.6 which is better for IDE's autocomplete function.

记忆里有你的影子 2024-08-25 12:24:04

我不是 PHP 5 非框架 ORM 的用户,但这里有一些很好的比较帖子(如果您还没有看到它们):

http://codeutopia.net/blog/2009/05/16/doctrine-vs-propel-2009-update/

http://trac.symfony-project.org/wiki/ComparingPropelAndDoctrine

两个结论最喜欢 Doctrine 作为 Symfony 的新一代 ORM。

I'm not a user of PHP 5 non-framework ORM, but here's some good comparison posts (in case you haven't seen them yet):

http://codeutopia.net/blog/2009/05/16/doctrine-vs-propel-2009-update/

http://trac.symfony-project.org/wiki/ComparingPropelAndDoctrine

Both conlusion favorite towards Doctrine as a newer generation of ORM for Symfony.

鲜肉鲜肉永远不皱 2024-08-25 12:24:04

使用 Propel 2 多年后,我更喜欢 Propel 2,而不是 Doctrine,这只是基于您构建查询逻辑的方式。学说是尽可能深入的,并且管理它的许多方面都与该深度水平相匹配。我觉得 Propel 有一种更流畅、更对象驱动的方式来构建和管理查询交互。

对我来说,这导致模型中的代码更少,并且围绕如何处理逻辑的结构更多。这导致只是将许多交互构建为通用功能。 (毕竟,您对数据库所做的 90% 都只是某种程度的增删改查操作。)

最后,两者都很强大、易于管理,并且都能完成工作。我的个人项目和兴趣使用 Propel ORM 2 和未来的项目,如果仍然用 PHP 编写,将会走这条路。

在过去的三四年里,我每天都在使用这两种产品。

After using both of them for a number of years I prefer Propel 2 to Doctrine simply based on how you construct your query logic. Doctrine is as in depth as it can get and managing many aspects of it match that level of depth. Propel I feel has a more fluid and object driven way of building and managing the query interactions.

For me this led to less code in the model and more structures around how logic can/will be processed. This resulted in just building out many interactions as common functionality. (After all 90% of what you will do with a database is just going to be some degree of crud operation.)

In the end, both are powerful, manageable and will get the job done. My personal projects and interest use Propel ORM 2 and future projects, if still written in PHP will go that route.

I've been using both on a daily basis for the past 3-4 years.

瘫痪情歌 2024-08-25 12:24:04

我建议使用 DbFinder 插件。这实际上是一个非常强大的插件,支持两者,并且非常强大。事实上,我比任何一个都更喜欢使用它。

I'd suggest using DbFinder Plugin. This is actually a very powerful plugin that supports both, and is quite a nice powerful. I actually like using it better than either.

末蓝 2024-08-25 12:24:04

如果我没记错的话,两个 ORM 都使用基于 XML 的模式,并且创建这些模式定义非常麻烦。如果您需要一个基于 PHP 且风格流畅的简单架构。您可以尝试 LazyRecord https://github.com/c9s/LazyRecord 它支持自动迁移和升级/降级脚本生成器。所有类文件都是静态生成的,没有运行时成本。

If I'm not wrong, both ORMs use XML-based schema, and creating these schema definition is pretty cumbersome. If you need a PHP-based simple schema with fluent style. You may try LazyRecord https://github.com/c9s/LazyRecord it supports automatic migration and upgrade/downgrade script generators. And all the class files are generated statically without runtime cost.

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