2

application.iniで次の動作を構成することは可能ですか?

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{
    protected function _initAdminModuleAutoloader()
    {

    $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Admin',
        'basePath'  => APPLICATION_PATH . '/modules/admin',
    ));
        $this->_resourceLoader->addResourceTypes(array(
            'model' => array(
                'namespace' => 'Model',
                'path'      => 'models'
            )
        ));
}

}
?>

もしそうなら、例を教えていただけますか?

ありがとう。

4

2 に答える 2

2

ここにいくつかの指針があります。最初に、application.ini ファイルに以下の行が必要です。

resources.modules.admin = "enabled"

これにより、Zend_Application_Resource_Modules の次の関数が確実に実行されます。

public function init()
{
    $bootstrap = $this->getBootstrap();
    $bootstrap->bootstrap('FrontController');
    $front = $bootstrap->getResource('FrontController');

    $modules = $front->getControllerDirectory();
    $default = $front->getDefaultModule();
    $curBootstrapClass = get_class($bootstrap);
    foreach ($modules as $module => $moduleDirectory) {
        $bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
        if (!class_exists($bootstrapClass, false)) {
            $bootstrapPath  = dirname($moduleDirectory) . '/Bootstrap.php';
            if (file_exists($bootstrapPath)) {
                $eMsgTpl = 'Bootstrap file found for module "%s" but bootstrap class "%s" not found';
                include_once $bootstrapPath;
                if (($default != $module)
                    && !class_exists($bootstrapClass, false)
                ) {
                    throw new Zend_Application_Resource_Exception(sprintf(
                        $eMsgTpl, $module, $bootstrapClass
                    ));
                } elseif ($default == $module) {
                    if (!class_exists($bootstrapClass, false)) {
                        $bootstrapClass = 'Bootstrap';
                        if (!class_exists($bootstrapClass, false)) {
                            throw new Zend_Application_Resource_Exception(sprintf(
                                $eMsgTpl, $module, $bootstrapClass
                            ));
                        }
                    }
                }
            } else {
                continue;
            }
        }

        if ($bootstrapClass == $curBootstrapClass) {
            // If the found bootstrap class matches the one calling this
            // resource, don't re-execute.
            continue;
        }

        $moduleBootstrap = new $bootstrapClass($bootstrap);
        $moduleBootstrap->bootstrap();
        $this->_bootstraps[$module] = $moduleBootstrap;
    }

    return $this->_bootstraps;
}

上記の関数では、モジュールのブートストラップが呼び出されます。/application/modules/admin に Bootstrap.php という名前のモジュール ブートストラップ ファイルがあり、次のコードが含まれている必要があります。

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{


}

いくつかの手順を省略しますが、継承クラスをたどると、Zend_Application_Module_Autoloader で次の関数が呼び出されます。

public function initDefaultResourceTypes()
{
    $basePath = $this->getBasePath();
    $this->addResourceTypes(array(
        'dbtable' => array(
            'namespace' => 'Model_DbTable',
            'path'      => 'models/DbTable',
        ),
        'mappers' => array(
            'namespace' => 'Model_Mapper',
            'path'      => 'models/mappers',
        ),
        'form'    => array(
            'namespace' => 'Form',
            'path'      => 'forms',
        ),
        'model'   => array(
            'namespace' => 'Model',
            'path'      => 'models',
        ),
        'plugin'  => array(
            'namespace' => 'Plugin',
            'path'      => 'plugins',
        ),
        'service' => array(
            'namespace' => 'Service',
            'path'      => 'services',
        ),
        'viewhelper' => array(
            'namespace' => 'View_Helper',
            'path'      => 'views/helpers',
        ),
        'viewfilter' => array(
            'namespace' => 'View_Filter',
            'path'      => 'views/filters',
        ),
    ));
    $this->setDefaultResourceType('model');
}

上記のリソース タイプはすべて、このパターンに従うすべてのモジュールでデフォルトでカバーされます。他に必要なものは、ブートストラップ ファイルでカスタマイズする必要があります。

于 2010-03-13T19:36:06.363 に答える
0

デフォルトのプロジェクト構成で Zend Framework バージョン 1.10.4 を使用しています。次の行を使用して、application.ini のすべてのモジュールをアクティブにします。

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

モジュール ディレクトリに Bootstrap.php があることが重要です。それがなければ、私のモデルは正しくロードされませんでした。ブラウザの URL は大文字と小文字が区別されるようです。例: http://example.com/Admin/controller/action

だから、それはうまくいくはずです...

于 2010-05-01T21:44:44.140 に答える