Zend 与现有的 Propel ORM

发布于 2024-10-24 11:46:33 字数 402 浏览 1 评论 0原文

我正在努力将一个相当大(但有些简单)的应用程序从 Symfony 转换为 Zend,由于数据库而很大。这也是我的第一个 Zend 项目,但到目前为止似乎进展顺利。该应用程序很简单,数据库相当复杂(我预计如果手动完成,需要花费很多时间进行数据映射)。

我拥有使用 Symfony FW 完成的所有原始源代码。原始版本使用 propel 并工作(并且有超过 200 个模型映射 DB,快速浏览 272 个)。

我的数据库表有一行又一行的依赖,我还重用了原始的数据库结构...直接导入表/模式,所以我想原始的 propel 在这方面仍然可以正常工作。

我的问题是,花时间尝试将旧应用程序的推进部分与我的新的基于 Zend 的应用程序版本一起使用是否值得?这应该是直接的冒险吗?

如果这能起作用,它可能会消除我生活中的许多不眠之夜:)

I'm working on converting a rather large (but somewhat simple) app from Symfony to Zend, large because of the DB. This is also my first Zend project, but it seems to be going well so far. The app is simple, the DB is fairly complex (I foresee many hours of datamapping ahead if done manually).

I have all the original source code that was done using the Symfony FW. The original uses propel and works (and has over 200 models mapping the DB, 272 at quick glance).

My DB tables have dependent row after row, I am also reusing the original DB structure...straight import of tables/schema, so I imagine that the original propel would still work fine in that respect.

My question(s) is/are, would it be time well spent trying to reuse the propel section of the old app w/ my new Zend based version of the app? Should this be straight forward venture?

If this could work, it may remove many sleepless nights from my life :)

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

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

发布评论

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

评论(3

妄想挽回 2024-10-31 11:46:34

模型类可以包含对 Symfony 类的引用,例如 sfMixer。它们是通过额外的 Propel 行为添加的在 Symfony 发行版中。由于 sfMixer 可能不会存在于您的新 Zend 项目中,因此这可能会导致错误。

但是,应该可以使用全新的 Propel 安装(在 Zend 中或在 Symfony 中禁用额外行为)重新生成模型,然后将您自己的用户可编辑类文件复制到空生成的类文件上。

如果您在 Zend 项目中使用与 Symfony 项目中相同版本的 Propel,那么这应该是开箱即用的(除非您编辑了 Base 类,但我假设您没有这样做)。如果您在 Zend 中使用较新版本的 Propel 来生成模型,那么当您访问已更改的受保护成员时,可能会出现兼容性问题。

The model classes can contain references to Symfony classes, like sfMixer. They are added by extra Propel behaviors in the Symfony distribution. Because sfMixer will probably not exist in your new Zend project, this can lead to errors.

However, it should be possible to re-generate your models with a clean Propel installation (in Zend, or in Symfony with the extra behaviors disabled), and then copy your own user-editable class files over the empty generated ones.

If you use the same version of Propel in your Zend project as you did in your Symfony project, this should work out of the box (unless you edited the Base classes, but I assume you did not do that). If you are using a newer version of Propel in Zend to generate the models, there might be compatibility issues if you access protected members that since have changed.

东北女汉子 2024-10-31 11:46:34

为了其他可能在这里查看的人的利益,我将回答我自己的问题......

我最终做的是安装最新版本的 Propel (1.5)。 Jan Fabry(上图)提到之前生成的模型(来自 SF 项目)可能存在残留元素,这也是我担心的问题。所以我在数据库上运行了“反向”并生成了新的架构/模型。

我当然会保留原始生成的模型以供参考,因为我正在重用现有的数据库。我还在之前的应用程序上运行了 phpDoc 构建,包括生成的 Propel 模型,这是一个很好的工具,可以查看之前所做的事情。作为“侧面”提示,我还在新生成的模型上运行了 phpDoc,现在我有了一种从 Propel 构建生成的新“自定义 db api”的“参考”文档……真的很酷!
已经存在一些架构问题,例如缺乏对 ENUM 类型的支持……但在 Propel v1.6 中出现。原始模型作为 Propel 如何与现有数据库一起使用的工作示例。我预计当问题出现时,将“手动”编辑新模式中的一些条目。

Propel v1.5 有一个新的“查询”API(由 Frosty Z 指出),它正在替换(或增强)我的新应用程序中的“条件”和“对等”。对于以前如何将数据库集成到应用程序的逻辑中,原始代码仍然是一个很好的模型(不是 MVC 模型),但我发现新版本的 Propels“查询”API 将提供很大的帮助。

我读到 Propel 在某处不支持“连接”,但我看到这个版本支持,并且还有许多其他新的和新的功能。 Propel 中有用的功能。值得注意的是,新 API 处理关系的方式。这些都在 Propel 的文档中,我很想使用它。对于“手动”界面来说,数据库有点大且复杂,因此 Propel 的“反向”功能也非常方便。

像这样的查询:

                    $Users = UsersQuery::create()
                  ->filterByLastName($LastName)
                  ->find(); // $Users is a PropelCollection object
                 return $Users;

正如 Frosty Z 所说,非常“好”,并且与使用 Zend_Db 或直接 PHP/MySQL 相比节省了大量编码,并且看起来比以前的“标准”、“对等”方式更简单。该片段来自 Propel Docs,它解决了让我在其他地方寻找解决方案的问题,有条件的发现似乎它的代码大小相对会增长。我已经可以看到根据 ACL 过滤结果是多么容易。

我的回答是解释为什么我不重复使用原始模型;缺乏新方法和新方法担心残留代码可能会导致错误或头痛,以及为什么我坚持使用 Propel(除了它看起来真的很好这一事实);我有一个可用的 ORM 的现有示例。真的,我可以说上面的两个答案都是我的答案。谢谢你们!

For the benefit of others who may look in here, I am going to answer my own question...

What I ended up doing is installing the latest version of Propel (1.5). Jan Fabry(above) mentioned that there may be residual elements to the previously generated models (from the SF project), and that was a concern of mine as well. So I ran a 'reverse' on the database and generated new schema/models too.

I am certainly keeping the original generated models close at hand for reference, as I am reusing the existing database. I also ran a phpDoc build on the previous app, including the generated Propel models and that is serving as a great tool to see what was done before. As a 'side' tip, I also ran phpDoc on my new generated models and I now have a sort of 'reference' doc to my new 'custom db api' that was generated from the Propel build...really cool!
There are some schema issues already, like the lack of support for ENUM types...but coming in v1.6 of Propel. The original models serve as a working example of how Propel was used with the existing database. I foresee editing 'by hand' a few entries in the new schema when the issues arrise.

The v1.5 of Propel has a new 'query' API (pointed out by Frosty Z) that is replacing (or enhancing) the 'criteria' and 'peer' in my new app. The original code still serves as a good model (not MVC model) as to how the database was integrated into the app's logic before, but I am finding that the new version of Propels 'query' API is going to be a big help.

I read that Propel does not support 'joins' somewhere, but I see that this version does, and there are many other new & useful features in Propel. Quite notably, the way that the new API handles relationships. It's all in the docs at Propel, and I'm eager to use it. The database is kinda large and complex for a 'manual' interface, so the 'reverse' feature of Propel was very handy as well.

Queries like this one:

                    $Users = UsersQuery::create()
                  ->filterByLastName($LastName)
                  ->find(); // $Users is a PropelCollection object
                 return $Users;

is quite "nice" as Frosty Z said, and saves a lot of coding compared to using the Zend_Db, or straight PHP/MySQL, and seems more simple than the former 'criteria', 'peer', way. That snippet came from the Propel Docs, and solves the problem that made me look elsewhere for a solution, a conditional find seemed that it was going to grow in code size comparatively. And I can already see how easy it will be to filter results in accordance with ACL's.

My answer is an explanation of why I'm not re-using the original models; lack of new methods & fear of residual code that may cause bugs or headaches, and why I stuck with Propel (besides the fact that it seems really nice); I have an existing example of a working ORM. Really, I can say that both answers above are what I went with. Thanks guys!

王权女流氓 2024-10-31 11:46:33

我认为你可以重用旧应用程序的 Propel 部分,因为 Propel 1.5(当前稳定)和下一个 1.6 向后兼容到 Propel 1.3(如果我没记错的话,由 Symfony 1.0 使用)及其原始的“Criteria”语法。

然后,您将受益于 Propel 1.5 的改进(其中包括漂亮的“查询”语法),而不会丢失现有代码。

请参阅:

I think that you can reuse the Propel sections of the old app, since Propel 1.5 (current stable) and the next 1.6 are backward compatible down to Propel 1.3 (used by Symfony 1.0 if I remember well) and its original "Criteria" syntax.

You will then benefit for the Propel 1.5 improvements (among them, the nice "Query" syntax), without losing the existing code.

See:

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