【问题标题】:Zend Framework 1.12 - can not load module's modelZend Framework 1.12 - 无法加载模块的模型
【发布时间】:2014-08-28 03:00:18
【问题描述】:

我有一个带有几个模块的 Zend Framework 1.12 应用程序。到目前为止,一切都运作良好。但是我想将映射器添加到我的应用程序中,但 Zend 框架找不到映射器类。

项目结构:

-application
   -modules
     -api
     -otms
       -models
         -Mapper
           FormToOnix2.php
         -FeedFile.php

映射器文件如下:

class Otms_Model_Mapper_FormToOnix2
{
   ...
}

在 application.ini 中我为自动加载添加了“Otms_”前缀:

autoloaderNamespaces.otms[]   = "Otms_"  

但是当我尝试从控制器创建映射器对象时

 $test = new Otms_Model_Mapper_FormToOnix2();

我收到以下错误消息

include_once(Otms/Model/Mapper/FormToOnix2.php): failed to open stream: No such file or directory in <b>/cloudware/library/Zend/Loader.php</b> on line 146

同时,如果我尝试创建另一个 Otms 模型的对象,例如:

$file = new Otms_Model_FeedFile();

一切正常。如何解决映射器加载问题?

【问题讨论】:

    标签: php zend-framework zend-autoloader


    【解决方案1】:

    好的,我阅读了Zend Documentation 关于自动加载器和模块资源加载器的信息。所以,

    Zend Framework ships with a concrete implementation of Zend_Loader_Autoloader_Resource            
    that contains resource type mappings that cover the default recommended 
    the directory structure for Zend Framework MVC applications.
    

    这个映射方案看起来像这样:

    forms/       => Form
    models/      => Model
        DbTable/ => Model_DbTable
        mappers/ => Model_Mapper
    plugins/     => Plugin
    services/    => Service
    views/
        helpers  => View_Helper
        filters  => View_Filter
    

    因此,如果您想添加一个带有映射器的目录,您应该将其命名为“映射器”而不是“映射器”。这解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      • 2021-06-01
      相关资源
      最近更新 更多