如何与多个项目共享 Symfony2 模型 [英] How to share a Symfony2 model with several projects

查看:25
本文介绍了如何与多个项目共享 Symfony2 模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建用于监控某些资产的 SaaS.这意味着它接收数据、保存数据并将其显示在网络界面中.

We are creating a SaaS that monitors certain assets. This means it takes in data, saves it, and displays it in a webinterface.

为此,我们使用/正在迁移到 Symfony2 创建一些组件:

For this, we have a few components that we created with/are moving to Symfony2:

  • 一个前端网络应用程序,用户可以在其中查看他们的数据
  • 后端管理网络应用程序,我们在其中创建新的监视器、用户等.
  • 一个 API
  • 从队列中检索接收到的数据并将其放入我们的数据库中的应用程序(现在这是一个单独的脚本,但我正在考虑将其重新编写为由 cron 调用的 Symfony 命令)

所有这四个应用程序共享相同的模型:我们的主数据库,其中包含所有用户、监视器和数据.

All these four applications share the same model: our main database that holds all the users, monitors, and data.

我的问题是:我应该如何在 Symfony2 中构建这些项目?

  1. 我是否创建了一个单独的包来保存我的数据库的实体,并让四个项目包含这些实体并使用它们?
  2. 我可以在我的 Symfony 应用程序文件夹中创建一个模型"目录,它被我的/src 目录中的所有包使用吗?
  3. 其他一些更简洁的方法来做到这一点?

选项 1 似乎有点奇怪,因为在我看来,bundle 需要路由、视图、控制器等.仅将它用于实体会有点奇怪.

Option 1 seems a bit weird, since a bundle, to my understanding, needs routing, views, controllers, etc. Using it for just entities would be a bit weird.

选项 2 似乎没问题,因为/app 文件夹对于/src 文件夹中的所有内容都被认为是公共的"(例如,因为参数也驻留在那里).但是,那里没有模型"文件夹,我不确定应该有吗?

Option 2 seems alright, since the /app folder is considered 'communal' anyway for everything that is in the /src folder (since, for example, parameters reside there as well). However, there is no 'model' folder there, and I'm not sure that there should be?

我知道 Symfony 2 已经很少有最佳实践"了,因为它是全新的.但我想看看在您看来,是否有任何做法比其他做法更可取.

I understand that there are very few 'best practices' out already for Symfony 2, since it's brand new. But I wanted to see if there are any practices more preferable then others, in your opinion.

欢迎提供任何反馈.提前致谢,

Any feedback is more then welcome. Thanks in advance,

节食者

推荐答案

我目前正在做的是第一个选项:为您的实体创建一个单独的包.这就是我存储装置、实体、表单和实体相关测试的地方.

What I am currently doing is the first option: create a separate bundle for your entities. That's where I store fixtures, entities, forms and entity-related tests.

捆绑包不需要需要路由、控制器、视图等.我实际上看到了一个蓝图捆绑包,它所做的只是随附了 blueprint-css 资源,因此它们可以很容易地在项目中重复使用.

A bundle does NOT need to have routing, controllers, views etc. I've actually seen a blueprint bundle, and all it does is ship blueprint-css resources with it so they can be easily reused in projects.

至于将模型添加到应用程序目录...我不喜欢那样.我将 app 目录视为所有配置应该放在的地方.尽管您可以覆盖 app/Resources 下的视图,但每当我想覆盖某些内容时,我都会创建一个新包.

As for adding models to the app directory... I wouldn't like that. I see the app directory as a place where all the configuration should be. Even though you can override views under app/Resources, whenever I want to override something I create a new bundle.

这篇关于如何与多个项目共享 Symfony2 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆