What is the correct or preferred directory structure for a Zend Framework 2 module?

Viewed 4992

I would like to get to grips with Zend Framework 2 by using it for a small project. I have been through various blogs articles, docs and of course the fantastic tutorial by Akrabat (Rob Allen).

However, in all my reading I have not come across any explanation on the correct or preferred directory structure for a module that Zend Framework 2 expects.

In the Akrabat tutorial Rob Allen's example module makes use of a single model and controller. The directory structure he chose was:

/module
    /Album
        /config
        /src
            /Album
                /Controller
                /Form
                /Model
        /view
            /album
                /album

This is all fine, but what if a module had multiple controllers and models as you would expect in a site that had multiple pages/sections? Would I put all my controllers in the /src/Album/Controller directory, or would I create another set of /src/xxx/ directories for each additional model and related controllers and views?

In the /view directories, do I break it up into sub-directories for each set of views used by the various controllers?

I think the confusion for me comes from the fact that in Rob's example, his main Controller/Model is the same name as the module. So his Album module has a directory, with more Album directories for the models, controllers and views. If I were to rename his module from Album to, say, MyModule would the directory structure then become:

/module
    /MyModule
        /config
        /src
            /Album
                /Controller
                /Form
                /Model
        /view
            /MyModule
                /album

Would it then follow that an additional model, Artist, and associated controllers would be organised thusly:

/module
    /MyModule
        /config
        /src
            /Album
                /Controller
                /Form
                /Model
            /Artist
                /Controller
                /Form
                /Model
        /view
            /MyModule
                /album
                /artist

If not the above, then what structure would it be?

This is of course all assuming ZF2 expects a strict structure. If this is not the case then obviously I can organise it pretty much the way I want.

1 Answers
Related