Page 1 of 1
MVC model - file directory as model?
Posted: Fri Jun 23, 2006 2:12 pm
by Luke
I am pretty new to the MVC model. I am rebuilding my File management system (that i just finished

without cakePHP). My question is basically this:
If I am working with files, won't my model be directories instead of a database? Would the file structure actually be the model? I am confused on how to approach this.
Posted: Sat Jun 24, 2006 2:35 am
by timvw
Should people really know that the data comes from a database? or a filesystem? Imho doesn't belong in the model but in the datalayer...
I would come up with a model where you have a (abstract) File class with properties as location, size, modification time, type, ...
And then in the concrete implementation i would use the filesystem, database, or whatever to provide access to the Files...
With this simple approach i first wrote a simple file browser. Afterwards i implemented a driver that used xml as source and the 'remote files' browser was completed with little effort...
Posted: Sat Jun 24, 2006 12:02 pm
by Christopher
Yes, in this case the data describing the file structure is the Model. Remember that the Model is often considered to be in the Domain Layer. Think of the Domain as what your program is about. If you are browsing lists then that is what the program "does." If you are browsing list of database records then "database records" is what the program is "about." In your case the program is "about" of files and directories.
Typically below the Domain Layer is the Data Layer. That is the data itself, so within you Model you would access the Data Layer to fetch the data. The Model then applies some organization to it -- often called "business rules." In your case the Data Layer only provides a list of files for a given directory -- your Model needs to maintain hierarchy information and attach file attributes as needed.
The Data Layer has no dependencies on the Domain Layer, and in turn the Domain Layer should have no dependencies on the layer above it -- the Presentation Layer (that's the V and C).
Typically all Domain Layers are implemented as some kind of Gateway class that provides a clean, purposeful, abstracted interface to the Domain.