简体   繁体   中英

Using Zend Framework and Doctrine with independend modular structures

I've seen a lot of articles about integrating ZF and Doctrine. There is also a proposal for ZF here but they have always two possible structures. Either they put all models into one top level model directory or they put it into a module related model directory.

application
|-- Bootstrap.php
|-- configs
|-- controllers
|-- models           - EITHER HERE
|-- modules
|   -- examplemodule
|       |-- controllers
|       |-- models   - OR HERE
|       |-- views
|-- views

For our projects I see problems for either of the two options:
1. One directory: application/models - in a complex system after a short time there will be hundreds of files, over all when you have the table classes two (eg User.php and UserTable.php).
2. Module based model directories: application/modules/examplemodule/models - in many cases we use models in multiple modules at the same time. So the "User" is required eg in the modules "game", "administration", ...

Is there a way to use some kind of sub directories under the top level directory "models" to get some grouping. It should be completely independent of the module structure.

application
|-- Bootstrap.php
...
|-- models
|   -- user
|       |-- User.php
|       |-- Friend.php
|       |-- other user related models
|   -- game
|       |-- Game.php
|       |-- Score.php
|       |-- ...
...

Any solution should support autoloading and the class generation from yaml files.

Any ideas, links or solutions? Thanks!

We are working on a solution to this at the company I work at right now.

We are following the Zend modular directory structure currently, and we have our models folder in each module directory, with a base directory like this:

|----application
|--------modules
|------------content
|----------------models
|--------------------Base
|------------------------Content.php
|--------------------Content.php

Our models autoload, but we haven't integrated the code generation into the zf cli, so we currently generate the models and then copy them into the module directory manually.

Sorry I don't have the exact answer you need, but you may also be interested in this proposal in the Zend Community.

I keep mine in one directory. As the saying goes, developer time is expensive, and CPU time is cheap, so optimize for the developer. Also, KISS, and YAGNI. Don't optimize until you need to optimize. Until then, trust auto loader.

For what it's worth, the site I use this on is fairly busy and performance has never been an issue.

Wouldn't the User Model belong to the User Module anyway? And shouldn't the Game Module more likely have some sort of Interface to connect to a User Model?

Like not directly using the User Model in the Game Module but rather passing a User Adapter to the Game Module by configuration?

To me after all, Modules make less sense when they are not interchangeable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM