-- Dodger <[email protected]> wrote
(on Wednesday, 30 September 2009, 12:14 PM -0700):
> File Name            Class Prefix        Base Prefix         Model Name
> ----------------------------------------------------------------------
> Post.php             Blog_Model_                             Post        
> (Blog_Model_Post)
> BasePost.php         Blog_Model_         Base                Post        
> (Blog_Model_BasePost)
> 
> But for ZF resource/module autoloading to work, the base class needs to be in 
> a
> different "namespace" (because it's in a different directory, and you can't
> specify two directories to look in for a single namespace). So I actually need
> to have a different class prefix for base classes. Perhaps something like:
> 
> File Name            Class Prefix        Base Prefix         Model Name
> ----------------------------------------------------------------------
> Post.php             Blog_Model_                             Post        
> (Blog_Model_Post)
> BasePost.php         Blog_BaseModel_     Base                Post        
> (Blog_BaseModel_BasePost)
> 
> ... but it's not possible to specify a different class prefix for base classes
> in Doctrine! (when using the code generation tools)
> 
> I'm not sure how to do this. The ZF resource/module autoloaders seem rather
> inflexible.
> 
> D.
> 
> P.S. The models are stored in application/modules/blog/models (and /models/
> generated for base models)

It's actually really easy:

    $al = Zend_Loader_Autoloader::getInstance();
    $al->registerNamespace('Doctrine');
    $al->pushAutoloader(array('Doctrine', 'autoload'), 'Doctrine_');

You also have to tell Doctrine it should autoload models:

    $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, 
Doctrine::MODEL_LOADING_CONSERVATIVE);
    $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);

and your table classes need to be in the same directory as your models
themselves:

    blog/
        models/
            Post.php
            PostTable.php

Then use a resource autoloader or module autoloader to do autoloading of
your model classes; everything at this point will work.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to