0


ZendFrameworkでマルチウェブサイトCMSに取り組んでいます。
Webサイト/アプリケーションフォルダーのapplication/フォルダーからモジュールをオーバーライドする必要があるところまで来ました。
私の問題のもう少し良い説明:これ
が私のアプリケーションのツリーです(重要な部分):

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

だから私がする必要があるのは、websites / website1.com /application/のmodule1/が存在する場合はアプリケーションのmodule1/をオーバーライドすることです。Webサイトフォルダー内のmodule1/内のすべてが、メインアプリケーションフォルダー内のすべてをオーバーライドするようにします。
また、このmodule1に2つのコントローラー(たとえば、IndexControllerとTestController)があり、module1 / controllersの下のwebsitesフォルダーにTestControllerのみを配置して、ApplicationフォルダーからTestControllerのみをオーバーライドし、メインフォルダーからIndexControllerを取得する場合も必要です。
私が達成しようとしていることを正確に説明できなかった場合は申し訳ありません。不明な点がございましたら、お問い合わせください。
ありがとうございました。

編集: オーケー、まず第一に-あなたのコメントに感謝します。
Webサイト/フォルダーを使用する理由は、主にvhostが原因です。これは、すべてのWebサイトに個別の(パブリック?)フォルダーがあることを好むためです。また、アプリケーションフォルダーを含む1つのライブラリを使用する理由は、明らかにアップグレードの理由です(たとえば、Zendをアップグレードします-すべてのWebサイトでアップグレードする必要はありません)。
コントローラーにオーバーライドオプションを使用することはめったにありません。もちろん、メインコントローラー(たとえば-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).
4

1 に答える 1

1

アップデート

私はあなたのディレクトリ構造を強くお勧めしませんが、それはあなたのアプリケーションであり、あなたはそれを好きなように構造化するべきです。

複数のコントローラーをロードするには、フロントコントローラープラグインを作成して、コントローラーディレクトリスタックにパスを追加する必要があります

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_pathsにスローできます
  • ファイルが存在することを確認し、フロントコントローラープラグインからロードします

カップルに名前を付ける。

于 2011-08-22T09:16:57.333 に答える