Question

I have 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);
    }
}

And I have file _controller/MySQL.php with Gold_MySQL.class. On windows system this code is working and including MySQL.php, but on hosting this code not working ((

[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

EDIT

How to make so that Unix could look at any files? Zend has no files with a lowercase letter.

Was it helpful?

Solution

Sounds like your filename is case sensitive and you're trying to load a file in the wrong case. i.e. you might need gold_mysql.php instead of Gold_MySql.php?

OTHER TIPS

It sounds like a case sensitive problem with the server filesystem. check paths and filenames for correct case.

linux/unix take care about case. windows does not.


note: This answers a previous version of the question

It could be that you're overriding the include path. In your index.php try something like

<?php

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

And remove the set_include_path() calls in your Autoloader class.

IMHO, If you are using Zend Framework, it would be better to write two separator autoloaders and push them to Zend's autoloader stack.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top