【发布时间】:2019-01-02 19:36:29
【问题描述】:
在一个 web MVC 项目中,我有以下结构:
mymvc/ -> Project root.
public/ -> Document root. The only one folder accessible from web.
assets -> Client-side assets. NOT ONLY for global themes and libraries, BUT ALSO for each specific "view" controlled by the "src/Application" components.
css/
js/
images/
...
index.php -> Application's entry point.
src/ -> UI layer rules.
Application/
Controller/
View/
ViewModel/
Dispatcher/ -> Application dispatching - route matching, dispatching to the specified controller, etc.
... -> Other classes used by the components in the "src/Application" folder.
templates/ -> Layout and template files.
注意:所有域模型组件(实体、存储库、数据映射器、服务等)都位于mymvc 目录之外的文件夹中,因此任何其他应用程序也可以访问它们。
我想过——实际上是很多——关于执行以下两个步骤:
- 将
templates目录移动到src/Application文件夹。 - 将
assets目录移动到src/Application,在Web 服务器(Apache) 配置中创建别名/assets/- 指向移动的文件夹,并允许外部世界对其进行完全访问。
全局使用的资产(如 css 主题、js 库代码或背景图像等)仍可能位于 public 目录中 - 显然不在名为或别名为 assets 的文件夹中。
我真的觉得这两个步骤是一个非常好的主意,因为在我看来,这两个文件夹都包含与来自src/Application 的结构相关的资源。
所以,不要有这样的东西:
src/Application/Controller/AboutUs.phppublic/assets/js/AboutUs.js-
templates/AboutUs/[multiple-layout-and-template-files],
类似以下的结构似乎要好得多:
src/Application/Controller/AboutUs.phpsrc/Application/assets/js/AboutUs.js-
src/Application/templates/AboutUs/[multiple-layout-and-template-files],
但是,在我研究了很多 Web 框架之后,我意识到它们都将两个文件夹(templates 和 assets)与应用程序文件夹完全分开。
所以我想问一下:有什么具体原因,为什么我提议的两个目录的移动不能,或者不应该做?
谢谢。
【问题讨论】:
-
您的网络资源(.js 等)肯定需要保留在公用文件夹中以允许用户访问它们。
-
对于可能会决定否决我的问题的用户:公平地说,让我知道您投反对票的动机,以便我可以相应地更改我的问题。我对您的所有建议或批评持开放态度。谢谢。
标签: php model-view-controller web-applications architecture directory-structure