The MVC pattern has absolutely nothing to do with your application's folder layout.
Whether you put all your files into one single folder or use a layout like shown in your question is completely irrelevant. It's not getting more or less MVC from it, because MVC is not about folders, but about splitting user interface interaction into three distinct roles.
Unless you are following a code convention that demands a certain file naming scheme (like PEAR), the only thing important for your application is that your Autoloader can find the files at runtime somehow. So if you think the layout shown above is good for you, go with it.
Your architectures should tell readers about the system, not about the frameworks you used in your system. If you are building a health-care system, then when new programmers look at the source repository, their first impression should be: “Oh, this is a heath-care system”. Those new programmers should be able to learn all the use cases of the system, and still not know how the system is delivered. They may come to you and say: “We see some things that look sorta like models, but where are the views and controllers”, and you should say: “Oh, those are details that needn’t concern you at the moment, we’ll show them to you later.”
I'm using a similar structure (with homemade framework too but backup out of webroot). You could maybe add a "form" folder in the private folder.
I use this to make controller more readable. The forms are generaly a big wall of object code. Putting them in an external file included in the controller is a good idea.
Don't forget to exclude the public folder from the rewriting rules and everything should be allright :)
An other solution is to put index.php in your public folder and define this folder as your webroot in nginx. It prevent remote access to all other file (like backup file) which should used only by the framework.
Quick note: I would stay away from public/private folders as you're essentially locking yourself into two roles. An ACL implementation would be difficult/confusing in this situation.
I guess administration and website is different modules of website.
Why dont you have a shared or core modules folder. For example, you have a database model named "User" and methods named createUser(), editUser(), listUsers(), changeRightsOfUser() and more more.. With this structure you need to write and abstract this model for all modules.
Your controllers is must be unique, this is okey. But models can be usable or extendable for every module.
发布评论
评论(4)
MVC 模式与应用程序的文件夹布局完全没有关系。
无论您将所有文件放入一个文件夹还是使用问题中所示的布局都是完全无关的。它并没有从中获得更多或更少的 MVC,因为 MVC 不是关于文件夹,而是关于分割用户界面交互分为三个不同的角色。
除非您遵循需要特定文件命名方案的代码约定(例如 PEAR),否则对您的应用程序来说唯一重要的是您的自动加载器可以在运行时以某种方式找到文件。因此,如果您认为上面显示的布局适合您,请使用它。
罗伯特“鲍勃叔叔”马丁建议您的文件夹布局应该表达该应用程序是关于什么的。:
The MVC pattern has absolutely nothing to do with your application's folder layout.
Whether you put all your files into one single folder or use a layout like shown in your question is completely irrelevant. It's not getting more or less MVC from it, because MVC is not about folders, but about splitting user interface interaction into three distinct roles.
Unless you are following a code convention that demands a certain file naming scheme (like PEAR), the only thing important for your application is that your Autoloader can find the files at runtime somehow. So if you think the layout shown above is good for you, go with it.
Robert "Uncle Bob" Martin suggests that your folder layout should express what the application is about.:
我正在使用类似的结构(也使用自制框架,但从网络根目录备份)。您可以在私人文件夹中添加一个“表单”文件夹。
我用它来使控制器更具可读性。这些表单通常是一堵巨大的目标代码墙。将它们放入控制器中包含的外部文件中是一个好主意。
不要忘记从重写规则中排除 public 文件夹,一切都应该没问题:)
另一种解决方案是将 index.php 放在你的 public 文件夹中,并将该文件夹定义为 nginx 中的 webroot。它防止远程访问仅应由框架使用的所有其他文件(例如备份文件)。
I'm using a similar structure (with homemade framework too but backup out of webroot). You could maybe add a "form" folder in the private folder.
I use this to make controller more readable. The forms are generaly a big wall of object code. Putting them in an external file included in the controller is a good idea.
Don't forget to exclude the public folder from the rewriting rules and everything should be allright :)
An other solution is to put index.php in your public folder and define this folder as your webroot in nginx. It prevent remote access to all other file (like backup file) which should used only by the framework.
快速说明:我会远离公共/私人文件夹,因为您基本上将自己锁定在两个角色中。在这种情况下,ACL 的实现会很困难/令人困惑。
Quick note: I would stay away from public/private folders as you're essentially locking yourself into two roles. An ACL implementation would be difficult/confusing in this situation.
我想管理和网站是网站的不同模块。
为什么你没有共享或核心模块文件夹。例如,您有一个名为“User”的数据库模型和名为 createUser()、editUser()、listUsers()、changeRightsOfUser() 等的方法。使用此结构,您需要为所有模块编写和抽象此模型。
您的控制器必须是唯一的,这没关系。但模型对于每个模块都是可用或可扩展的。
I guess administration and website is different modules of website.
Why dont you have a shared or core modules folder. For example, you have a database model named "User" and methods named createUser(), editUser(), listUsers(), changeRightsOfUser() and more more.. With this structure you need to write and abstract this model for all modules.
Your controllers is must be unique, this is okey. But models can be usable or extendable for every module.