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

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

问题描述

我们正在创建一个SaaS来监控某些资产。这意味着它接收数据,保存它,并将其显示在web界面中。

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:


  • 一个前端网络应用程序,用户可以在其中查看其数据


  • 一个从队列中检索接收到的数据并将其放入我们的数据库的应用程序。
  • (这现在是一个单独的脚本,但我正在想将它改为由cron调用的Symfony命令)
  • a frontend web application, where users can view their data
  • a backend administrative web application, where we create new monitors, users, etc.
  • an API
  • an application that retrieves the received data from a queue and puts it in our database (this is now a seperate script, but I'm thinking of reworking this as a Symfony command that is called by cron)

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

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

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


  1. 我是否创建一个独立的包,其中包含我的数据库的实体,并且有四个项目包括这些实体并与它们一起工作?


  2. 一些其他更清洁的方法来做这个?

选项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文件夹中的所有内容都被认为是公用的(因为例如参数驻留在那里好)。但是,没有'model'文件夹,我不确定应该有吗?

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,

Dieter

推荐答案

我目前做的是第一个选项:为您的实体创建一个单独的捆绑包。
这是我存储fixture,实体,表单和实体相关测试的地方。

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 / 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天全站免登陆