draxq02664 2010-06-04 14:25
浏览 18
已采纳

Zend不是自动加载模型

Ok, this is driving me nuts!

I have a directory structure as follows:

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

My config file looks like this

[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[] =

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.

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

Ideas?

Thanks

  • 写回答

4条回答 默认 最新

  • duan88014 2010-06-04 22:04
    关注

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

    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 - 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"
    

    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;
    }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统