Zend 模块中的自动加载器找不到表单?

发布于 2024-11-29 09:08:07 字数 2035 浏览 0 评论 0原文

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

我正在尝试从模块结构中的 PasswordController 加载 EditPassword ,如下所示。

项目结构

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

我正在控制器中加载表单,如下所示:

$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 中的其他所有内容似乎都运行相当合理的默认值 - 我是否真的必须声明每个模块的所有表单/模型/viewhelpers 路径,因为它们遵循默认的 Zend 结构,并且在默认模块目录中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不回头走下去 2024-12-06 09:08:07

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

class Account_Bootstrap extends Zend_Application_Module_Bootstrap
{
}

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

resources.modules[] = 

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

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.

就是爱搞怪 2024-12-06 09:08:07

Bootstrap.php

'basePath' =>应用程序路径。 'modules/acount'

应为:

'basePath' =>应用程序路径。 'modules/account'

其他一切看起来都不错

In Bootstrap.php

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

Should be:

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

Everything else looks ok

静若繁花 2024-12-06 09:08:07

如果这是从您的实际配置复制/粘贴,那么您在 'modules/acount' 中存在拼写错误。

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

根据您的 ZF 版本,您甚至不需要引导程序中的自动加载器。您可以将其删除。 ini 中的以下内容具有相同的作用。

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文