jsuggs wrote:
> I know this has been discussed a couple of times but maybe not quite in this
> aspect. Where do your models live in a modular application?
It's important to understand a few concepts about modularity. For
various people, it can be said to have one of two, or both goals:
1) to create a reusable set of code that can be used as a springboard
for new applications. For example, like a Blog Module that has all of
the common "blog" functionality, but simply needs to be tailored and
customized to fit into a new site/application
and/or
2) To achieve a hMVC structure where there is more hierarchy in the
code, each level of hierarchy adding some logical separation of
concerns. This allows for more manageable, more maintainable code since
each module/hierarhcy has been group according to some set of common
goals, concerns and responsibility.
> Assumptions for discussion:
> Modules: default, blog, and admin.
> Namespace: App_ (horrible, but makes it easier to follow)
>
> For models that will span responsibilities in all of the modules (ex.
> Users), do they live in the App namespace or in the Default namespace
> (namespace may be used incorrectly in this case)?
> App_Model_User => /application/models/User.php
> Default_Model_User => /application/modules/default/models/User.php
>
> Additionally, what about models specific to a module (ex. BlogPost)? Should
> they "live" in the blog module or does all of the models live in the
> Application namespace and the modules just access what they need when
> appropriate?
>
> I start to get my head wrapped around some concepts then I end up having
> "basic" questions that end up throwing me for a loop. Then again, this
> could be another one of those "whatever works for you" scenarios as well...
Here is a project that demonstrates a basic applicaiton with a top level
MVC, and modules directory. (this was created with Zend_Tool on the
command line):
|- .zfproject.xml
|- application
| |- Bootstrap.php
| |- configs
| | `- application.ini
| |- controllers
| | |- ErrorController.php
| | `- IndexController.php
| |- models
| | `- User.php [Application_Model_User]
| |- modules
| | `- Blog
| | |- controllers
| | |- models
| | | `- BlogPost.php [Blog_Model_BlogPost]
| | `- views
| | |- filters
| | |- helpers
| | `- scripts
| `- views
| |- helpers
| `- scripts
| |- error
| | `- error.phtml
| `- index
| `- index.phtml
|- docs
| `- README.txt
|- library
|- public
| |- .htaccess
| `- index.php
`- tests
|- application
| `- bootstrap.php
|- library
| `- bootstrap.php
`- phpunit.xml
> Sidebar discussion: I would think that this answer [c|w]ould apply to
> service classes as well, but please correct me if I'm wrong.
It depends on what type of service classes you are talking about. If
you are talking about Service Locator/Layer classes, these classes very
much align their responsibilities up with that of a model.
If these are Service API classes, ie: classes that are intended to be
used with an RPC server of some sort, ZF has traditionally had an "apis"
directory at the same layer of models, views, and controllers directories.
Hope this gets you going,
Ralph
没有评论:
发表评论