简体   繁体   English

Symfony2-AdminBundle实际上是组织应用程序的正确方法吗?

[英]Symfony2 - Is an AdminBundle actually the correct way to organise the app?

I'm new to Symfony and am starting an app which includes an admin section. 我是Symfony的新手,正在启动一个包含管理部分的应用程序。 The general advice is pretty obvious - make an AdminBundle. 一般建议非常明显-制作一个AdminBundle。

However, is that really the best practice? 但是,那真的是最佳实践吗? The Symfony documentation is saying that a bundle is intended to be a 'plugin' that can be distributed as is, and will work in another app. Symfony文档说捆绑软件旨在成为一个“插件”,可以按原样分发,并且可以在另一个应用程序中使用。 Doesn't the admin section need to be aware of all the models and things for the main app though? 管理员部分是否不需要了解主应用程序的所有模型和内容? It's an admin section created to administer changes specifically to my app, so how would it be distributable or self-contained? 这是一个管理部分,专门用于管理对我的应用程序所做的更改,因此如何分配或自包含?

I feel like I'm missing something because if all the advice is to make an AdminBundle then I obviously don't understand something or haven't delved far enough into Symfony yet. 我觉得我正在丢失某些东西,因为如果所有建议都是制作一个AdminBundle,那么我显然不了解某些东西,或者对Symfony的研究还不够深入。

I'm just looking to get my app started with the correct structure going forward. 我只是想让我的应用程序以正确的结构开始。

FYI, I created a project with the default AppBundle as well. 仅供参考,我还使用默认的AppBundle创建了一个项目。 I was just planning to make everything in there, but that doesn't seem right either as it will be harder to organise all the admin stuff separately. 我只是打算将所有内容都放入其中,但这似乎也不对,因为单独组织所有管理人员将变得更加困难。

I think it depeneds on tour needs and size of your project. 我认为这取决于旅游需求和项目规模。 Creating a special bundle to put there logic for of admin panel is a good practice. 创建一个特殊的软件包来放置管理面板的逻辑是一个好习惯。 But if you have a small application with just couple of entities it's not necessary to create AdminBundle. 但是,如果您的小型应用程序只有几个实体,则不必创建AdminBundle。

Symfony provides you any way you prefer to do what you need. Symfony为您提供了您喜欢做的任何方式。 You can create bundle or put all the admin panel business logic into special directory inside your main bundle controller directory or put all code into the same controllers and manage permissions to admin actions by setting up firewall. 您可以创建捆绑软件或将所有管理面板业务逻辑放入主捆绑软件控制器目录内的特殊目录中,或将所有代码置于相同的控制器中,并通过设置防火墙来管理对管理员操作的许可权。

I would suggest to use AdminBundle. 我建议使用AdminBundle。 It lets you keep your code cleaner: a client logic in one bundle, an admin logic is in another. 它可以使您的代码保持整洁:一个客户端逻辑位于一个捆绑中,一个管理逻辑位于另一个捆绑中。

Bundle description taken from symfony official documentation isn't saying any opposite things. 从symfony官方文档中获得的捆绑软件描述没有说相反的话。 Because if you want you can use your AdminBundle in another app. 因为如果您愿意,可以在另一个应用程序中使用AdminBundle。 Bundle is a way to keep different kind of business logic separated of each other. 捆绑包是一种使不同种类的业务逻辑彼此分离的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM