I'm getting pretty fed up with Zend's autoloader.

I'm trying to load EditPassword from within PasswordController in the module structure as shown below.

project structure

application.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"

Bootstrap.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;
}

I'm loading the form in the controller like this:

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

The error itself is:

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

What am I doing wrong? Everything else in Zend seems to run off fairly sane defaults - do I really have to declare all the paths to forms/models/viewhelpers for each module, given that they're following the default Zend structure, and in the default modules directory?

有帮助吗?

解决方案

I would remove all the module autoloading code from the app Bootstrap and then implement an empty module bootstrap in application/modules/account/Bootstrap.php:

class Account_Bootstrap extends Zend_Application_Module_Bootstrap
{
}

Then in application/configs/application.ini, add the following:

resources.modules[] = 

The idea here is that Zend_Application_Module_Bootstrap automatically registers a resource autoloader with bunch of common path/namespace mappings, including the one for forms that you are using.

其他提示

In Bootstrap.php

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

Should be:

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

Everything else looks ok

If this a copy/paste from your actual config then you have a typo in 'modules/acount'

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

Depending on your ZF version you don't even need the autoloader in the bootstrap. You can remove it. The following in your ini does the same.

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top