ZF-4167: Zend_Db_Table_Row_Abstract does not properly rely on autoloading
Description
Zend_Db_Table_Row_Abstract->findDependentRowset() and Zend_Db_Table_Row_Abstract->findParentRow() rely on Zend_loader::loadClass() for loading dependent and parent tables. This makes it impossible to use autoloading to find these classes and forces the developer to add all paths that may contain DB Table class to be added to the include_path.
In my application I have a custom loader which I registered with Zend_Loader::registerAutoload('My_Model_Loader'). However this loader never gets fired when working with dependent and parent tables because autoloading is not used within Zend_Db_Table_Row_Abstract.
Autoloading should be used before directly trying to load a class. With the proposed MVC filder structure there would be a model folders for each application module. Adding each model folder as an include path is less than ideal. Following a pattern similar to controller actions, it would be reasonable that someone would want to load a model from a specific module.
I'm able to get my application to work just fine by commenting out the try...catch that tries to load the class.
Comments
Posted by Keith Pope (mute) on 2009-01-23T00:14:49.000+0000
Linking these issue as they report the same problem
Posted by Keith Pope (mute) on 2009-01-23T00:21:27.000+0000
Hi,
I would really like to see this included, also I believe this could become a blocker to Matthews Resource Autoloader proposal as this uses the autoloader.
Thx
Keith
Posted by Keith Pope (mute) on 2009-02-07T09:40:36.000+0000
Attaching a patch for this issue, this is just a proof of concept for now and therefore no unit tests etc. This may be a good temporary fix until all the class loading problems have been sorted out.
Patch Purpose
Remove Zend_Loader dependency
Patch Details
Patched From std trunk
The idea is that it works in a similar way to the setDefaultAdpater, the loader is either null (use autoloader) or a valid callback array. All the Zend_Db_Table classes then use Zend_Db_Table_Abstract::loadClass() to load their classes.
Posted by Keith Pope (mute) on 2009-03-04T04:46:47.000+0000
I am currently creating a new patch which is simpler after talking to Matthew about it.
Posted by Keith Pope (mute) on 2009-03-05T05:15:39.000+0000
Right here is my second attempt at patching this issue :)
I have simplified by just wrapping the Zend_Loader class in class_exists that use the autoloader.
Patch is from the 1.7.6 release and includes:
Patched Db Table files Unit tests Documentation
Hopefully I have got it right, see what you think.
Posted by Jamal Fanaian (jamal) on 2009-04-13T10:19:08.000+0000
This issue affects the use of the Zend_Application_Module_Autoloader in ZF 1.8.0.
Posted by Keith Pope (mute) on 2009-04-13T13:01:58.000+0000
The easiest way to fix this is to change the following in Loader.php
if (class_exists($class, false) || interface_exists($class, false)) {
to
if (class_exists($class) || interface_exists($class)) {
any ideas why it does not check the autoloader by default?
Posted by Matthew Weier O'Phinney (matthew) on 2009-05-14T05:44:49.000+0000
Resolved in trunk and 1.8 release branch