1

我正在尝试将表单与模块一起使用,它们应该存储在模块内。所以起初我的文件结构:

application/
   (...other directories)
   modules/
       group/
          controllers/
             IndexController.php
             (...controllers)
          forms/
             Create.php
          views/
             scripts/
                (...view scripts)
          Bootstrap.php

在 IndexController 中,我试图通过以下方式设置表单

new Group_Form_Create()

Create.php 中的类当然是 Group_Form_Create。我收到以下错误消息:

Fatal error: Class 'Group_Form_Create' not found in (...)\application\modules\group\controllers\IndexController.php on line 380

带有 Group_Bootstrap 类的 Bootstrap.php 只是一个空类。实际上,我使用的是默认的 Zend 结构,但无论如何它都不起作用。问题出在哪里或可能的解决方案有什么想法?

4

3 回答 3

3

在我的模块引导程序(APPLICATION_PATH/modules/group/Bootstrap.php)中,如果使用以下代码:

    //Loads the autoloader resources
    $this->_moduleName = 'group';
    $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
            'basePath' => APPLICATION_PATH ."/modules/".$this->_moduleName."/",
            'namespace' => '',
            'resourceTypes' => array(
                    //Tells the application where to find the forms
                    'form' => array(
                            'path' => 'forms/',
                            'namespace' => ucfirst($this->_moduleName).'_Form_'
                    ),
                    //Tells the application where to find the models
                    'model' => array(
                            'path' => 'models/',
                            'namespace' => ucfirst($this->_moduleName).'_Model_'
                    )
            )
    ));

然后我像这样调用表格或模型:

$frm = new Group_Form_Create();

我在所有模块中都使用了相同的代码段,并且只更改了 $this->_moduleName; 的值。每一次。

希望这可以帮助 !

于 2012-07-23T12:57:53.020 回答
1

听起来您的模块引导程序没有运行。这些是由模块资源触发的,如果您有以下内容,则会加载该资源:

resources.modules[] = ""

在你的application.ini. 因此,如果它不存在,请添加它。

于 2012-07-23T13:32:30.327 回答
0

理想情况下,它应该开箱即用。

在你的引导程序中添加这个:

protected function _initAutoload() {

    $autoloader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Group_',
        'basePath' => dirname(__FILE__),
      ));

    Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
    return $autoloader;

}

于 2012-07-23T12:19:15.570 回答