【发布时间】:2012-08-30 08:21:29
【问题描述】:
将 Symfony2 用于我的结构之一。我想将模块和与模块相关的各种文件从其他模块文件中抽象出来。
例如。我有前端应用程序。在前端应用程序下,我有用户、图库模块。我想将所有与用户相关的文件保存在一个地方,将所有与画廊相关的文件保存在一个地方。通过这种方式,我实现了模块级别的抽象,就像 Symfony1.4 中提供的那样。
以下是我到这里实现的文件夹结构。
web/
admin.php
frontend.php
apps/
autoload.php # this autloads the common libaries/vendors for all application eg. CommonBundle
admin/
AppKernel.php
AppAutoload.php # load application specific libraries
bootstrap.php.cache
config/
cache/
.
.
.
frontend/
AppKernel.php
AppAutoload.php
bootstrap.php.cache
config/
cache/
.
.
.
src/
Admin/
UserBundle/
Controller/
UsersController.php
Entity/
User.php
Repository/
UserRepository.php
Resources/
views/
indexUserView.twig.html
DiaryBundle/
Controller/
DiaryController.php
Entity/
Diary.php
Repository/
DiaryRepository.php
Resources/
views/
indexDiaryView.twig.html
Frontend/
UserBundle/
Controller/
UsersController.php
Entity/
User.php
Repository/
UserRepository.php
Resources/
views/
indexUserView.twig.html
DiaryBundle/
Controller/
DiaryController.php
Entity/
Diary.php
Repository/
DiaryRepository.php
Resources/
views/
indexDiaryView.twig.html
我对上述文件夹结构很有信心。但是当我发现 Symfony2 社区支持在应用程序级别而不是在模块级别创建 Bundle 时,我想知道在模块级别创建 Bundle 的优缺点。模块级别的创建可能会出现哪些坑?
我可以看到为模块提供捆绑包的许多优点
-
一个模块的所有Controller、Views、Models都在同一个地方,并且从其他模块的Controller、Models、Views中抽象出来。这样,在一个模块上工作的人必须只在一个文件夹内工作,而不必担心模块2中正在进行的工作,即Bundle2
-
可以在应用程序级别使用以下命令清除缓存,仅用于前端应用程序
shell> php apps/frontend/console cache:clear -
如果您需要在前端应用程序中创建捆绑包,命令如下。它在 src/frontend 应用程序下创建 UserBundle。它还在 apps/frontend/AppKernel.php 中注册包名称。
shell> php apps/frontend/console generate:bundle --namespace=frontend/userBundle --format=yml
所以一切看起来都很好。但似乎 Symfony2 社区并不认为这种做法是正确的?
请在我的方法中提出漏洞?
【问题讨论】:
标签: architecture symfony symfony-1.4