Zend Framework - Zend_Db_Table and Zend_Loader
I am using Zend Framework and have a different directory structure than normal. I separate modules into a folder in /home and have website specific code in in an app folder for that website. In other words, /home/__common/app/blog would be where code for a blog sits that is used across many websites. And could for one respective site would sit in /home/website/app.
This has worked fine, as I can set the module directory in my bootstrap : $front->addModuleDirectory(MODULE_PATH);. But Zend_Db_Table_Abstract uses Zend_Loader to call Rowset and Row classes. When I define a custom Row or Rowset class from my modules, Zend_Loader throws an Exception, as it is hard coded to call Zend_Loader. Even though I have the logic built in my _autoload function in my bootsrap to handle my directory structure, Zend_Loader bypasses this, which is frustrating. This bug report has the same issue and identifies a workaround by modifying Zend_Loader, which I don’t want to do, as I don’t want to have to modify Zend_Loader every time I checkout the latest version of the code.
Hopefully the patch will get applied, in the meantime I am manually requiring my Row and or Rowset class in my Class that extends Zend_Db_Table_Abstract, and that solves the problem (although the Row class is now “loaded” even when it may not be needed).
Update : I was able to get it working without an include in the model class by putting a symlink from the website’s model directory to the model directory in the app. Part of the reason this problem came up is my unique directory structure and the way I am naming model classes in my modules. To make things work with my __autoload, I append the module name to the model class. I.e. a class called Post in the Blog module would be named Blog_Post - that makes it easy to figure out where to find the class in my __autoload function in the bootstrap. I guess I could add all the modules to the include path, but that would require a lot of rework. I initially decided not to do just that, as it seemed like that would add a lot of paths to the default include path, and would require the include path to be updated every time I needed to use a new module. I guess if I ran a benchmark and having 10 extra paths in the include path didn’t matter, it would have been smarter to do it that way, since I now have to add a symlink everytime I want to use a module.