-1

The model is not a class or any single object. It is a very common mistake to make [...], because most frameworks perpetuate this misconception.

So, what is the best folder structure for the models?

The Zend Recommended Project Directory Structure, for example, has only a "model" folder. But when I try to separate my models into Domain Objects, Data Mappers and Services, how should this structure look like?

Thanks!

Community
  • 1
  • 1
grundig
  • 101
  • 2
  • 14

2 Answers2

0

I think this is subjective, but I will give you my way of doing it. I keep the models directory and then create different sub-directories for each module of the application. It would look something like the following:

application
  - controllers
  - models
     - authentication
         - services
         - mappers
         - ...
     - mail
         - services
         - mappers
         - ...
     ... (other directories)
  - views
  - templates

I feel this gives a nice separation of each module while keeping everything inside the models directory which other developers are properly used to.

I dont know if this is the best or most effective solution, but I think with proper use of namespaces it proves quite easy to manage. I have also learned that if you make proper use of the SOLID principle you can (almost) copy/paste the different directories/modules to other projects without much hastle.

A little series created by TutsPlus, which explains the SOLID principle in detail by using theory and a concrete example.

I hope this can help you the right direction. Best regards.

AnotherGuy
  • 605
  • 11
  • 20
-1

In Zend Framework you can create "modules" which can integrate their own models.

application/
    configs/
        application.ini
    controllers/
        helpers/
    forms/
    layouts/
        filters/
        helpers/
        scripts/
    models/
    modules/
         Domain Objects/
           controllers/
           models/
         Data Mappers/
           controllers/
           models/
         Services/
           controllers/
           models/
    services/
    views/
        filters/
        helpers/
        scripts/
    Bootstrap.php

As you can see, each module has also controllers and views associated.

Finally, you have to add these models to your bootstrap's autoloader :

// Admin
    $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
        'basePath' => APPLICATION_PATH . '/modules/Domain Objects',
        'namespace' => 'Domain Objects'
    ));

    $resourceLoader->addResourceType('controller', 'controllers/', 'Controller')->addResourceType('model', 'models/', 'Model');
DoubleMiP
  • 71
  • 4