Zend无法自动加载模型 [英] Zend not autoloading models

查看:53
本文介绍了Zend无法自动加载模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这真让我发疯!

我的目录结构如下:

application
- modules
-- default
--- controllers
--- models
---- DbTable
---- Cachmapper.php
--- views

我的配置文件如下

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =

该应用程序似乎正常工作,如果我导航到localhost,它将正确地转到索引控制器.但是,由于某种原因,它拒绝加载任何模型.

The application seems to work, if I navigate to localhost, it correctly goes to the index controller. But, for some reason it refuses to load any models.

致命错误:在.............................../application/modules/default中找不到类'Model_Cachmapper'/controllers/IndexController.php,第26行

Fatal error: Class 'Model_Cachmapper' not found in .............................../application/modules/default/controllers/IndexController.php on line 26

想法?

谢谢

推荐答案

以下是适用于ZF 1.10.x的工作版本(至少其中一个),并且可能更早.

Here's a working version (one of them, at least), for ZF 1.10.x and probably earlier, too.

index.php

index.php

<?php
// Define path to application directory

defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

application.ini-相关部分

application.ini - the relevant parts

autoloadernamespaces[] = Zend_
includePaths.library = APPLICATION_PATH "/../library"

; Where will Zend_Application find the Bootstrap file
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

; Where are all the modules
resources.frontcontroller.moduledirectory = APPLICATION_PATH"/modules"
resources.modules[] = ""
; And which is the default module
resources.frontcontroller.defaultmodule = "default"

以及在application/Bootstrap.php

and in application/Bootstrap.php

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

/**
 * Autoloader for the "public" module
 * 
 * @return Zend_Application_Module_Autoloader
 */
public function _initPublicAutoload()
{
    $moduleLoader = new Zend_Application_Module_Autoloader(
                            array(
                                'namespace' => '',
                                'basePath' => APPLICATION_PATH . '/modules/default'
                            )
                        );

    return $moduleLoader;
}
}

这篇关于Zend无法自动加载模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆