Php Zend框架-覆盖模块

Php Zend框架-覆盖模块,php,zend-framework,zend-loader,Php,Zend Framework,Zend Loader,我正在Zend框架中开发多网站CMS。 我已经到了需要覆盖网站/应用程序文件夹中应用程序/文件夹中的模块的地步。 更好地解释我的问题: 下面是我的应用程序树(重要部分): 所以我需要做的是module1/in-website1.com/application/override module1/in-application,如果它存在的话。我希望模块1/网站文件夹中的所有内容都覆盖主应用程序文件夹中的所有内容。 我还想知道这个模块1中是否有2个控制器(例如IndexController和TestC


我正在Zend框架中开发多网站CMS。
我已经到了需要覆盖网站/应用程序文件夹中应用程序/文件夹中的模块的地步。
更好地解释我的问题:
下面是我的应用程序树(重要部分):

所以我需要做的是module1/in-website1.com/application/override module1/in-application,如果它存在的话。我希望模块1/网站文件夹中的所有内容都覆盖主应用程序文件夹中的所有内容。
我还想知道这个模块1中是否有2个控制器(例如IndexController和TestController),如果我在模块1/Controller下的网站文件夹中只放置TestController,则只覆盖应用程序文件夹中的TestController,并从主文件夹中获取IndexController。
对不起,如果我没有解释清楚我想要达到的目标。如果有不清楚的地方,请询问。
非常感谢。

编辑: 好的,首先-感谢您的评论。
拥有网站/文件夹的原因主要是因为vhost,因为我更喜欢我的所有网站都有单独的(公共?)文件夹,而拥有一个带有应用程序文件夹的库的原因显然是因为升级原因(例如,当我升级Zend时,我不需要为每个网站升级它)。
我很可能很少对控制器使用覆盖选项,是的,我甚至更喜欢扩展主控制器(例如-IndexController)并覆盖某些函数,但我认为这比覆盖整个类要困难得多。
下面是我的应用程序的完整结构:

 library/ - Library folder contains Zend and many other classes that I'll use in my application.
     Zend - Zend Framework
     MyCMS - Classes from my old CMS.
 sites/ - Folder that contains websties.
     website_1 - Website one.
         application/ - Application folder for website one. If I need to redefine module or something. So, if I need to override module: main_module, I'll  create folder main_module here with files that I want to override.
         config/ - Configuration for website_1 - if I need to override, for example, application.ini
         lang/ - Language files for this specific website.
         templates/ - Templates folder for website (layouts and templates). By the way, I'm using smarty.
             default/ - Main template.
                 layout/ - Layouts for Zend View.
                 css/
                 js/
                 images/
                 modules/
         files/ - Place to upload files in, for this website. This will contain user avatars and stuff.
         index.php - Main file that runs bootstrap and application.
         Bootstrap.php - Inherited bootstrap. In case I need to override some functions from default bootstrap.
 application/ - Main folder that contains application modules and stuff.
    main_module/
         configs/ - Module configuration.
             config.ini
         controllers/ - Controllers for this module.
         modules/ - Submodules. There are like boxes that I display on website. For example, if my main module is "news", here, I'll make new sub-module to display box with statistics.
             submodule/
                 services/ - XML/JSON/whatever service. If someone targets controller in services with specific parametars, it'll return response in requested format.
                     controllers/ - Services will only have controllers.
                 configs/ - Configuration for this submodule.
                 controllers/ - Controllers for this submodule.
                 models/ - Models for this submodule.
                 lang/ - Language files for this submodule.
                 template/ - Templates for this submodule.
                     helpers/
                     css/
                     js/
                     images/
                     index.html
         models/ - Models for main module.
         lang/
         services/  - Main module will also have services. See submodule services for explanation.
             controllers/
         template/
             helpers/
             css/
             js/
             images/
             index.html
     Bootstrap.php  - This is main bootstrap file that every website's bootstrap file will extend (and override some methods - if needed).
更新 尽管我强烈反对你的目录结构,但它是你的应用程序,你应该按照你喜欢的方式构造它

要加载多个控制器,您应该创建一个前端控制器插件,向控制器目录堆栈添加路径

class My_Controller_Plugin_Paths extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch()
    {
        // Something like this...
        // Would be best to load paths via config/database or somewhere
        $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
        $dispatcher->addControllerDirectory('/path/to/website1.com/controllers')
                   ->addControllerDirectory('/path/to/website2.com/controllers');
    }
}
这完全没有经过测试,但你明白了。只需确保在引导程序中向前端控制器注册插件


我同意@Laykes的观点。这是一个结构糟糕的应用程序

我不确定您的确切要求,但如果它是我的应用程序,我会尝试这样构造它:

/application
    /modules
        /default
            /controllers
                /IntexController.php      // Default_IndexController
                /Website1com
                    /IndexController.php  // Default_Website1com_IndexController (possibly extends Default_IndexController)
在这里,您可以看到结构正确的类继承,而无需创建完全独立的(可能是重复的)应用程序文件夹

自动加载类似的内容完全取决于您和您的优先级。你可以做很多事情,每个都有自己的+ve和-ve

  • 您可以按所需顺序将所有路径放入include_路径中
  • 检查文件是否存在并从前端控制器插件加载

举几个例子。

我很抱歉,但对于创建多站点CMS来说,这是一个非常糟糕的设计。就像你看了Drupals multisite然后复制了它一样。(这并不是一场旨在引导你的狂欢)。你的网站为什么存在?为什么不在我们的数据库或ini文件中创建一个新的“网站”,然后按预期使用主机名路由器(用于此确切目的)。非常感谢您的输入,这是一个很好的答案。它不仅仅是我的应用程序,我也没有真正为它创建整个结构(很少有开发人员在开发它)。如果您能澄清为什么这是一个糟糕的文件夹结构,我将不胜感激(除了给定的原因-很可能有多个代码)?再次感谢你的回答!1) 很可能有重复的代码。2) 解耦的“子网站”结构将使其难以维护和更新。3) 应用程序应位于应用程序文件夹中,控制器位于控制器文件夹中等。单独的应用程序文件夹应仅保留给完全不同的应用程序(可能共享同一库)。最后一点注意:我认为当你的网站增长时,你会发现维护起来非常困难。就像我说的,每个人都有自己的。
/application
    /modules
        /default
            /controllers
                /IntexController.php      // Default_IndexController
                /Website1com
                    /IndexController.php  // Default_Website1com_IndexController (possibly extends Default_IndexController)