Hi Matthew,

Yes, I read that info in your blog. Unfortunately, my requirements differ.

1. At the moment, I'm not using table classes.
2. I need generated base classes to be autoloaded.

You say: "Then use a resource autoloader or module autoloader to do
autoloading of
your model classes; everything at this point will work." -- but isn't that
the reason for enabling Doctrine autoloading? Why do it twice?

Also, according to the Doctrine documentation, "Conservative model loading
requires that each file contain only one class, and the file must be named
after the class. For example, if you have a class named User, it must be
contained in a file named User.php." -- which would mean that the file name
would have to be "Blog_Model_Post.php", which is a bit long and ugly.

Shouldn't the Zend resource/module autoloaders allow you to specify more
than one folder for classes? Like:

'model' => array(
        'paths' => array('models/', 'models/generated/'),
        'namespace' => 'Blog_Model'
)

Or, you could enable searching in subdirectries:

'model' => array(
        'path' => 'models/',
        'includeSubdirectories' => true,
        'namespace' => 'Blog_Model'
)

Thoughts?

D.


Matthew Weier O'Phinney-3 wrote:
> 
> -- Dodger <glen...@gmail.com> 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            | matt...@zend.com
> Zend Framework          | http://framework.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Autoloading-Doctrine-models-base-models-tp25687101p25706039.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to