【问题标题】:Autoload models, forms inside modules in zend framework在zend框架中自动加载模型,模块内的表单
【发布时间】:2012-06-16 11:18:41
【问题描述】:

我的应用结构是这样的:

  • 申请
    • 模块
      • 默认
      • 学生
        • 控制器
        • 表格
          • studentParent.php
        • 型号
        • 观看次数
        • Boostrap.php

我在学生模块的表单文件夹中有一个 studentParent.php。

class Student_Form_studentParent extends Zend_Dojo_Form{
}

每当我在学生模块的控制器中调用这个表单类时,我都会收到类未找到错误 我已将 Bootstrap.php 放在学生模块中。

class Student_Bootstrap extends Zend_Application_Module_Bootstrap
{

}

这是我的 application.ini 文件配置

resources.frontController.params.displayExceptions = 0
resource.modules=""
resources.view = ""
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "main_template"

我的 Bootstrap.php 文件:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
     protected function _initDefaultModuleAutoloader()
     {
         $moduleLoader = new Zend_Application_Module_Autoloader(
    array(
        "namespace" => '',
        "basePath"  => APPLICATION_PATH.'/modules/default'
        )
      );

          Zend_Controller_Action_HelperBroker::addPrefix('App_Action_Helper');

          return $moduleLoader;
     }
}

【问题讨论】:

    标签: zend-framework zend-autoloader


    【解决方案1】:
    resource.modules=""
    

    应该是:

    resources.modules=""
    

    (即资源复数)。

    我还建议你使用大写字母来开始你的类名,所以Student_Form_StudentParent 而不是Student_Form_studentParent(文件名也需要是StudentParent.php)。我想是个人偏好,但如果框架以一种方式执行,而您的应用程序以另一种方式执行,那么您的类命名将不一致。

    【讨论】:

      【解决方案2】:

      还有

      $moduleLoader = new Zend_Application_Module_Autoloader(
      array(
          "namespace" => '',
          "basePath"  => APPLICATION_PATH.'/modules/default'
          )
        );
      

      basePath 应该指向包含模块的目录,而不是像您的示例中那样指向特定的模块目录。

      【讨论】:

      • 实际上模块自动加载器应该指向模块目录,他的内容是正确的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多