2015-01-09 53 views

回答

0

我认为这是主观的,但我会给你我做这件事的方式。我保留models目录,然后为应用程序的每个模块创建不同的子目录。它看起来像下面这样:

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

我觉得这给了每个模块的一个很好的分离,同时保持其其他开发人员正确地使用到models目录中的一切。

我不知道这是否是最好或最有效的解决方案,但我认为正确使用名称空间证明它很容易管理。我还了解到,如果您正确使用SOLID principle,您几乎可以将不同的目录/模块复制/粘贴到其他项目中,而无需太多的ha。。

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

我希望这可以帮助你正确的方向。 此致敬礼。

-1

在Zend Framework中,您可以创建可以集成自己模型的“模块”。

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 

正如你所看到的,每个模块也有控制器和视图关联。

最后,你必须将这些模型添加到您的引导程序的自动加载磁带机:

// 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');