PHP:为未来的扩展和变化选择ORM?

发布于 2024-09-15 10:16:37 字数 354 浏览 5 评论 0原文

我有 Codeigniter MVC 背景,我们已经使用该背景一段时间了。是时候为一个大项目推出我们自己的框架了,但是我们现在已经到了数据库部分,并且立即感到有点困惑。
在 Codeigniter 中,我们对所有 SQL 数据库连接使用了 ActiveRecord,效果很好,但由于它不是一个单独的部分,我们正在寻找一个 ORM 解决方案,以便在我们的模型中编写尽可能少的代码来获得我们的结果。来自数据库的数据。

我们已经审查了包括 Doctrine2 和 Propel 在内的主要替代方案,但我们对这些配置文件以及这些库的实际范围感到非常害怕。

从维护角度来看,选择一个需要编辑比明显的 MVC 多得多的文件的 ORM(在推出架构更改时)真的很明智吗?

I come from a Codeigniter MVC background that we've been working with for some time now. It's time to roll our own framework for a big project, but we have come now to the Database part and got a bit confused immediately.
In Codeigniter, we've used the ActiveRecord for all SQL database connections, which has worked well, but since it's not a separate part, we are on the search for a ORM solution to write as little code as possible in our models to get our data from the databases.

We have reviewed the major alternatives including Doctrine2 and Propel, but we're quite scared by the fact of those configuration files and how extensive these libraries really are.

Is it really good sense, from a maintenance-wise perspective to choose an ORM that requires editing in so many more files then the obvious MVC's when a schema change is rolled out?

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

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

发布评论

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

评论(3

初与友歌 2024-09-22 10:16:37

说实话,propel 和doctrine 可能是目前市场上最好的 php ORM,我使用与 symfony 框架捆绑在一起的 propel,但是一旦你了解了文档,它确实会产生巨大的差异,并且这两个 ORM 都知道如何排除在外当您需要本机 sql 时,可以按您的方式使用。我建议您从两者中选择一个(推进/理论),然后投入时间并阅读文档,最终结果将是值得的。

Truth be told, propel and doctrine are perhaps the best php ORM in the market right now, I use propel which is bundle with symfony framework but once you have covered the documentation it really makes a huge difference and the both ORMs know how to stay out of your way when you need native sql. I would recommend you pick one(propel/doctrine) from the two and just invest time and go through the documentation, the end result will be worth it.

凯凯我们等你回来 2024-09-22 10:16:37

好吧,实际上对于 Propel,当您更改架构时,您不必编辑许多文件(如果您坚持使用基本的 ORM)。您只需更新数据库架构文件 (schema.xml),然后运行 ​​propel-gen,该工具就会在您指定的文件夹(在 build.properties 中)中为您创建必要的 Propel 类。

om 文件夹中的 BaseXXX 类永远不应该被编辑,因为每次更改架构并运行 propel-gen 时它们都会被覆盖。只需将您的业务逻辑添加到主文件夹中的类(默认情况下继承基类),它们仅创建一次,之后不会被 propel-gen 触及。

Well, actually for Propel you don't have to edit many files when you change your schema (if you stick to basic ORM use). You just update your database schema file (schema.xml), afterwards run propel-gen and that tool will create the necessary Propel classes for you, in the folder you specified (in build.properties).

The BaseXXX classes in the om folder should never be edited, because they will be overwritten every time you change your schema and run propel-gen. Just add your business logic to the classes in the main folder (which per default inherit the Base classes), they are only created once and will not be touched by propel-gen afterwards.

夜深人未静 2024-09-22 10:16:37

有了原则,您基本上可以只依赖 schema.yml 文件(YAML 格式)。使用该文件,学说能够生成 SQL、模型类、过滤器……一切(当然,如果您愿意,您可以修改这些文件,但在大多数情况下您不会)

And with doctrine you can basically just rely on the schema.yml file (YAML format). Using that file, doctrine is able to generate the SQL, the model classes, the filters, .... everything (of course then you can modify the files if you want but in most scenarions you won´t)

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