tags:

views:

123

answers:

1

I want to use a single Doctrine install on our server and serve multiple websites. Naturally the models should be maintained in the websites' modelsfolder.

I have everything up (and not running) like so:

Doctrine @

/CustomFramework/Doctrine

Websites @

/var/www/vhosts/custom1.com/
/var/www/vhosts/custom2.com/

Generating works fine, all models are delivered in /application_folder/models and /application_folder/models/generated for the correct website.

I've added Doctrine::loadModels('path_to_models') in the bootstrap file for each website, and also registered the autoloaded.

But....

This is the autoloader code:

public static function autoload($className)
{
    if (strpos($className, 'sfYaml') === 0) {
        require dirname(__FILE__) . '/Parser/sfYaml/' . $className . '.php';
        return true;
    }

    if (0 !== stripos($className, 'Doctrine_') || class_exists($className, false) || interface_exists($className, false)) {
        return false;
    }

    $class = self::getPath() . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

    if (file_exists($class)) {
        require $class;

        return true;
    }

    return false;
 }

Am I stupid, or is the autoloader really doing this:

$class = self::getPath() . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

or, in other words: Does it require me to have ALL my generated doctrine classes inside the Doctrine app directory? Or in other words, do I need a single Doctrine installation for each website?

I'm getting an error that the BaseXXX class cannot be found. So the autoloading doesn't function correctly. I really hope i'm doing something wrong.. anyone?

+2  A: 

Starting from Doctrine 1.2, the models autoloading is dealt by another autoloader, Doctrine_Core::modelsAutoload. This allows you to separate your library loading and models loading (if you want to use some other autoloader for loading the library classes).

reko_t
Nice, but if I change this: spl_autoload_register(array('Doctrine', 'autoload')); to this: spl_autoload_register(array('Doctrine', 'modelsAutoload')); then the library classes aren't loaded anymore :).
Ropstah
Correction, you were right! However, it's very important to call loadModels() at the END OF THE BOOTSTRAP FILE! :)
Ropstah