自动加载模型,在 zend 框架中的模块内形成



我的应用程序结构是这样的:

  • 应用
    • 模块
      • 违约
      • 学生
        • 控制器
        • 形式
          • 学生家长.php
        • 模型
        • 视图
        • 助推拉普.php

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

class Student_Form_studentParent extends Zend_Dojo_Form{
}

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

class Student_Bootstrap extends Zend_Application_Module_Bootstrap
{
}

这是我的应用程序.ini文件配置

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

我的引导.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;
     }
}
resource.modules=""

应该是:

resources.modules=""

(即资源复数)。

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

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

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

最新更新