0

我已经厌倦了 Zend 的自动加载器。

我正在尝试EditPasswordPasswordController模块结构内部加载,如下所示。

项目结构

应用程序.ini

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.baseUrl = "/"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"  
phpSettings.date.timezone = "Europe/London"

引导程序.php:

public function init() {
    $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
    $baseUrl = $config->baseHttp;
    define('BASE_URL', $baseUrl);
}

protected function _initAutoload() {
    $autoLoader = Zend_Loader_Autoloader::getInstance();
    $autoLoader->registerNamespace('App_');
    //
    $moduleLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath' => APPLICATION_PATH . 'modules/account',
            'resourceTypes' => array(
                    'form' => array(
                            'path' => 'forms',
                            'namespace' => 'Form'))));
    $autoLoader->pushAutoloader($moduleLoader);
    //
    return $autoLoader;
}

我正在像这样在控制器中加载表单:

$form = new Account_Form_EditPassword();
$this->view->form = $form;

错误本身是:

Fatal error: Class 'Account_Form_EditPassword' not found in 
Z:\dat\docs\workspace\metamusic\application\modules\account\controllers\PasswordController.php
on line 7

我究竟做错了什么?Zend 中的其他所有内容似乎都使用了相当合理的默认值——考虑到它们遵循默认的 Zend 结构并在默认的模块目录中,我真的必须为每个模块声明表单/模型/视图助手的所有路径吗?

4

3 回答 3

6

我将从应用程序 Bootstrap 中删除所有模块自动加载代码,然后在以下位置实现一个空模块引导程序application/modules/account/Bootstrap.php

class Account_Bootstrap extends Zend_Application_Module_Bootstrap
{
}

然后在 中application/configs/application.ini,添加以下内容:

resources.modules[] = 

这里的想法是Zend_Application_Module_Bootstrap自动注册一个资源自动加载器,其中包含一堆常见的路径/命名空间映射,包括您正在使用的表单的映射。

于 2011-08-13T02:25:46.283 回答
0

Bootstrap.php中

'basePath' => APPLICATION_PATH . 'modules/acount'

应该:

'basePath' => APPLICATION_PATH . 'modules/account'

其他一切看起来都不错

于 2011-08-12T23:41:35.067 回答
0

如果这是您实际配置的复制/粘贴,那么您有错字'modules/acount'

'basePath' => APPLICATION_PATH . 'modules/acount',

根据您的 ZF 版本,您甚至不需要引导程序中的自动加载器。你可以删除它。您的 ini 中的以下内容也是如此。

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
于 2011-08-12T23:41:50.363 回答