views:

541

answers:

3

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 (e.g. 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 e.g. 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!

+1  A: 

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.

Travis
Thanks Travis, the problem here is that with this it's unclean to use a model in module A from within module B and that's the frequently the case for us. In order to NOT invent a completely non ZF solution we stick with the "one model folder on top level"-solution and live with many files in one folder ...
stefax
A: 

I didn't try it but maybe this would solve a part of the problem http://www.doctrine-project.org/documentation/manual/1_2/en/yaml-schema-files#features-examples:packages:package-custom-path

Joeri
A: 

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.

lo_fye
Yep, that's how we decided to do it in the end. The model directory of our system contains now lots of files (around 200 or more) so navigating through and looking for specific models in the IDE is sometimes annoying, but on the other hand nobody has to think about which sub directory to be used for a certain model (because sometimes several sub directories would be appropriate) ...
stefax