Hi Juozas, I sent you an e-mail but I haven't received a reply – did you receive it?
D. Juozas wrote: > > Hi Dodger, > > I recommend generating models which are compatible with autoloading. It's > not that hard and requires much less hacking than setting up Zf > autoloading > to work in completely different way it was made for. > > For example, I have successfully done that by writing my own plugin and > task > for Doctrine. What it does, is simply generates files like: > > file: application/models/Name.php > class: Model_Name > > file: application/models/NameTable.php > class: Model_NameTable > > file: application/models/Base/Name.php > class: Model_Base_Name > > I was asked a few (dozens) times to blog about it, but because of crazy > work > load didn't managed to do that, so if you want to see actual code - drop > me > an email and I will send it to you. > > Have a nice day, > Juozas > > On Thu, Oct 1, 2009 at 10:36 PM, Dodger <[email protected]> wrote: > >> >> 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 <[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/ >> > >> > >> >> -- >> 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. >> >> > > -- View this message in context: http://www.nabble.com/Autoloading-Doctrine-models-base-models-tp25687101p25754541.html Sent from the Zend Framework mailing list archive at Nabble.com.
