0

我有index.php

<?php
    include('_controller/Autoloader.php');
    Gold_Autoloader::init();

    $mysql = new Gold_MySQL();

_controller/Autoloader.php

<?php
class Gold_Autoloader
{

    public static $loader;

    public static function init()
    {
        if (self::$loader == NULL)
            self::$loader = new self();

        return self::$loader;
    }

    public function __construct()
    {
        spl_autoload_register(array($this, 'controller'));
        spl_autoload_register(array($this, 'resources'));
    }

    public function resources($className)
    {
        $className = preg_replace('#Gold_#', '', $className);
        $className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);

        set_include_path(PROJECT_ROOT . '_resources');
        spl_autoload_extensions('.php');
        spl_autoload($className);
    }

    public function controller($className)
    {
        $className = preg_replace('#Gold_#', '', $className);
        $className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);

        set_include_path(PROJECT_ROOT . '_controller');
        spl_autoload_extensions('.php');
        spl_autoload($className);
    }
}

我有文件_controller/MySQL.php和 Gold_MySQL.class。在 Windows 系统上,此代码正在运行,包括 MySQL.php,但在托管此代码时不起作用((

[Thu Jan 27 12:55:57 2011] [error] PHP Fatal error: Class 'Gold_MySQL' not found in /home/u91167/youd0main.com/www/index_.php on line 5

编辑

如何使 Unix 可以查看任何文件?Zend 没有小写字母的文件。

4

3 回答 3

3

听起来您的文件名区分大小写,并且您尝试以错误的大小写加载文件。即你可能需要gold_mysql.php而不是Gold_MySql.php

于 2011-01-27T10:08:27.480 回答
2

这听起来像是服务器文件系统的区分大小写的问题。检查路径和文件名是否正确。

linux/unix 关心大小写。窗户没有。


注意:这回答了问题的先前版本

于 2011-01-27T10:08:31.987 回答
0

可能是您覆盖了包含路径。在你的 index.php 中尝试类似

<?php

set_include_path(
    implode(PATH_SEPARATOR,
    array(
        realpath('./_controller'),
        realpath('./_resources'),
        get_include_path()
    ))
);

并删除 Autoloader 类中的 set_include_path() 调用。

恕我直言,如果您使用 Zend 框架,最好编写两个分隔自动加载器并将它们推送到 Zend 的自动加载器堆栈。

于 2011-01-28T01:32:47.037 回答