Zend Framework - 覆盖模块

时间:2011-08-22 09:01:08

标签: php zend-framework zend-loader


我正在使用Zend Framework中的多网站CMS 我已经到了需要从我的网站/应用程序文件夹中的application /文件夹覆盖模块的位置 对我的问题有一个更好的解释:
    这是我申请的树(重要部分):

library/
application/
        module1/
            controllers/
            models/
            ....
        module2/
            controllers/
            models/
            ....
websites/
  website1.com/
       application/
            module1/
                controllers/
                models/
                ....

所以我需要做的是在network / website1.com / application / override module1 / application中的module1 /,如果存在的话。我希望module1 /在website文件夹中的所有内容都覆盖主应用程序文件夹中的所有内容 我也想,如果这个module1中有2个控制器(例如IndexController和TestController),并且我只将TestController放在module1 / controllers下的website文件夹中,从Application文件夹中覆盖ONLY TestController,并从主文件夹中获取IndexController。 /> 对不起,如果我没有解释我正在努力实现的目标。如果有不清楚的地方,请询问 谢谢。

修改 哦,首先 - 感谢您的评论 有网站/文件夹的原因,主要是因为我更喜欢我的所有网站都有单独的(公共?)文件夹,并且有一个库与应用程序文件夹的原因是因为,显然,升级原因(所以,当我,为例如,升级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).

1 个答案:

答案 0 :(得分:1)

更新

即使我强烈反对你的目录结构,它也是你的应用程序,你应该根据自己的喜好构建它。

要加载多个控制器,您应该创建一个Front Controller Plugin来添加到控制器目录堆栈的路径

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

这完全没有经过测试,但你明白了。只需确保在引导程序中使用Front Controller注册插件


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

我不确定您的确切要求,但如果是我的应用程序,我会尝试将其结构如下:

/application
    /modules
        /default
            /controllers
                /IntexController.php      // Default_IndexController
                /Website1com
                    /IndexController.php  // Default_Website1com_IndexController (possibly extends Default_IndexController)

在这里,您可以看到正确结构化的类继承,而无需创建完全独立且可能重复的应用程序文件夹。

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

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

为一对夫妇命名。