1

我现在有点失落。我尝试建立自己的库,但自动加载器似乎无法以某种方式工作。这里的这个例子是我找到的最接近的,但所有的解决方案都对我不起作用。

这是我的文件夹结构。

-application
 |_modules
  |_vita
   |_controllers
    |_IndexController.php
-data
-docs
-library
 |_ND
 ||_Model
 | |_Vita
 |  |_Vita.php
 |_Zend
-public
-tests

这是我的引导程序。

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{    
    ...

    protected function _initAutoloader()
    {
        $loader = Zend_Loader_Autoloader::getInstance();
        $loader->registerNamespace('ND_');
        return $loader;
    }

    ...
}

这是我完整的 application.ini (我知道 autoloaderNamespaces 指令与引导程序中的指令是双重的,但它不适用于两者单独使用它们中的每一个

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path       = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class      = "Bootstrap"
appnamespace         = "Application"

; automatic loading of libraries 
autoloaderNamespaces[] = "ND_"

phpSettings.date.timezone = "Europe/Berlin"

;resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/index/controllers"
;resources.frontController.params.displayExceptions = 0

;appnamespace = "Application"
resources.frontController.moduleDirectory            = APPLICATION_PATH "/modules"
resources.frontController.params.prefixDefaultModule = true
resources.frontController.defaultModule              = "index"
resources.frontController.throwerrors                = false
resources.frontController.params.displayExceptions   = 0

; resources (modules)
resources.modules[] = ""
resources.view[]    = ""


; resources (layout)
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout     = "main"

; db settings
resources.db.adapter           = "PDO_MYSQL"
resources.db.isDefaultAdapter  = true
resources.db.params.host       = "localhost"
resources.db.params.username   = "root"
resources.db.params.password   = ""
resources.db.params.dbname     = "nd"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

这是我的控制器,我尝试实例化类“Vita”但我总是收到此错误:“致命错误:C:\xampp\htdocs\ND\application\modules\vita\controllers\IndexController 中找不到类 'ND_Model_Vita_Vita' .php 在第 17 行"

class Vita_IndexController extends Zend_Controller_Action
{
    public function init()
    {
        $this->view->headTitle('Vita');
    }

    public function indexAction()
    {
        /* Just to try if the Loader is working for the Zend library -> it works */
        $this->newForm = new Zend_Form();


        $this->mdlVita = new ND_Model_Vita_Vita();
        Zend_Registry::get('log')->info($this->mdlVita->test());
    }
}

这就是 Vita 课程

class ND_Model_Vita_Vita
{
    public function test()
    {
        return 'Is working';
    }
}

使用模块时有什么我可能忽略或必须记住的吗?我很感谢任何建议。

编辑:我缩小了与 xampp 环境有关的问题。我将项目推送到一个 live-apache 位置,它在那里工作

4

0 回答 0