MVC Folder Structure
Posted: Wed Apr 28, 2010 2:35 pm
I've been using a super-simple model/view/controller concept for a few small sites lately but now I want to use it on a big one. Thing is, I really don't like the layout of the typical mvc folders when there a lot of view files involved.
I can't decide if I want to use a folder structure like this:
models/
views/
controllers/
with lots of each item in each folder
or a structure like this
models/foo.php
models/bar.php
models/tig.php
AdminAreaFoo/controller.php
AdminAreaFoo/viewA.php
AdminAreaFoo/viewB.php
AdminAreaFoo/viewC.php
AdminAreaBar/controller.php
AdminAreaBar/viewA.php
AdminAreaBar/viewB.php
AdminAreaTig/controller.php
AdminAreaTig/viewA.php
AdminAreaTig/viewB.php
AdminAreaTig/viewC.php
AdminAreaTig/viewD.php
Where each folder contains the controller and all views necessary for a major section of the site. All related items all in one spot with no unrelated things distracting me.
I'm working on an administration area that has the following main sections.
Contracts
MemberEmployees
MemberCompanies
Resources
Services
Jobs
Links
MemberMail
Resumes
Each one of these section will be mostly structured like this:
1. Index Page
Intro text, recently added/edited records & search form.
2. Advanced Search Form Page
Page with much larger search form
3. Search Results Page
Small Search form, search results & pagination
4. Edit Record Form Page
Form for editing an existing record
5. Add Record Form Page
Form for adding a new record. In some cases the Edi & Add form will use the same View file utilizing IFs for the minor differences. Other cases will have very different forms for adding and editing.
6. Add/Edit Record Success Feedback Page
Notify the user that thier data was saved. Show a quick overview of the just added/edited record.
7. Delete Record Warning Page
Notify the user that they are about to delete a record. Show a quick overview of the record so they know they click the right one. Show a big DELETE button.
8. Delete Feedback Page
Notify the user that the record was deleted. Show a list of other data that was "attached" to that record (photos, documents) indicating that these files are now orphans and may be left in the orphaned attachments category or deleted.
Even if I wind up re-using some view files in multiple areas I'll still have about 5 view files for eac area. Using the 1st folder structure that'll look like:
models/Contracts.php
models/MemberEmployees.php
models/MemberCompanies.php
models/Resources.php
models/Services.php
models/Jobs.php
models/Links.php
models/MemberMail.php
models/Resumes.php
controllers/Contracts.php
controllers/MemberEmployees.php
controllers/MemberCompanies.php
controllers/Resources.php
controllers/Services.php
controllers/Jobs.php
controllers/Links.php
controllers/MemberMail.php
controllers/Resumes.php
views/contract_index.php
views/contract_advancedSearch.php
views/contract_results.php
views/contract_edit.php
views/contract_add.php
views/contract_success.php
views/contract_delete.php
views/contract_attachments.php
views/jobs_index.php
views/jobs_advancedSearch.php
views/jobs_results.php
views/jobs_edit.php
views/jobs_add.php
views/jobs_success.php
views/jobs_delete.php
views/jobs_attachments.php
views/links_index.php
views/links_advancedSearch.php
views/links_results.php
views/links_edit.php
views/links_add.php
views/links_success.php
views/links_delete.php
views/links_attachments.php
views/MemberEmployees_index.php
views/MemberEmployees_advancedSearch.php
views/MemberEmployees_results.php
views/MemberEmployees_edit.php
views/MemberEmployees_add.php
views/MemberEmployees_success.php
views/MemberEmployees_delete.php
views/MemberEmployees_attachments.php
...etc
.... you get the idea.
The views folder done this way just looks so messy to me.
What do you do when you have a large site with a lot of views?
I can't decide if I want to use a folder structure like this:
models/
views/
controllers/
with lots of each item in each folder
or a structure like this
models/foo.php
models/bar.php
models/tig.php
AdminAreaFoo/controller.php
AdminAreaFoo/viewA.php
AdminAreaFoo/viewB.php
AdminAreaFoo/viewC.php
AdminAreaBar/controller.php
AdminAreaBar/viewA.php
AdminAreaBar/viewB.php
AdminAreaTig/controller.php
AdminAreaTig/viewA.php
AdminAreaTig/viewB.php
AdminAreaTig/viewC.php
AdminAreaTig/viewD.php
Where each folder contains the controller and all views necessary for a major section of the site. All related items all in one spot with no unrelated things distracting me.
I'm working on an administration area that has the following main sections.
Contracts
MemberEmployees
MemberCompanies
Resources
Services
Jobs
Links
MemberMail
Resumes
Each one of these section will be mostly structured like this:
1. Index Page
Intro text, recently added/edited records & search form.
2. Advanced Search Form Page
Page with much larger search form
3. Search Results Page
Small Search form, search results & pagination
4. Edit Record Form Page
Form for editing an existing record
5. Add Record Form Page
Form for adding a new record. In some cases the Edi & Add form will use the same View file utilizing IFs for the minor differences. Other cases will have very different forms for adding and editing.
6. Add/Edit Record Success Feedback Page
Notify the user that thier data was saved. Show a quick overview of the just added/edited record.
7. Delete Record Warning Page
Notify the user that they are about to delete a record. Show a quick overview of the record so they know they click the right one. Show a big DELETE button.
8. Delete Feedback Page
Notify the user that the record was deleted. Show a list of other data that was "attached" to that record (photos, documents) indicating that these files are now orphans and may be left in the orphaned attachments category or deleted.
Even if I wind up re-using some view files in multiple areas I'll still have about 5 view files for eac area. Using the 1st folder structure that'll look like:
models/Contracts.php
models/MemberEmployees.php
models/MemberCompanies.php
models/Resources.php
models/Services.php
models/Jobs.php
models/Links.php
models/MemberMail.php
models/Resumes.php
controllers/Contracts.php
controllers/MemberEmployees.php
controllers/MemberCompanies.php
controllers/Resources.php
controllers/Services.php
controllers/Jobs.php
controllers/Links.php
controllers/MemberMail.php
controllers/Resumes.php
views/contract_index.php
views/contract_advancedSearch.php
views/contract_results.php
views/contract_edit.php
views/contract_add.php
views/contract_success.php
views/contract_delete.php
views/contract_attachments.php
views/jobs_index.php
views/jobs_advancedSearch.php
views/jobs_results.php
views/jobs_edit.php
views/jobs_add.php
views/jobs_success.php
views/jobs_delete.php
views/jobs_attachments.php
views/links_index.php
views/links_advancedSearch.php
views/links_results.php
views/links_edit.php
views/links_add.php
views/links_success.php
views/links_delete.php
views/links_attachments.php
views/MemberEmployees_index.php
views/MemberEmployees_advancedSearch.php
views/MemberEmployees_results.php
views/MemberEmployees_edit.php
views/MemberEmployees_add.php
views/MemberEmployees_success.php
views/MemberEmployees_delete.php
views/MemberEmployees_attachments.php
...etc
.... you get the idea.
The views folder done this way just looks so messy to me.
What do you do when you have a large site with a lot of views?