Hello! > -----Original Message----- > From: James Dempster [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 18, 2008 11:18 PM > To: Simeon Goranov > Cc: [email protected] > Subject: Re: [fw-general] autoloading models
> $frontController = Zend_Controller_Front::getInstance(); > $frontController->addModuleDirectory(ROOT_DIR.'/modules/'); As I understand the code in Controller/Front.php addModuleDirectory() only makes the front controller aware of the module's controller directory and has nothing to do with model class autoloading. > On Tue, Mar 18, 2008 at 11:55 PM, Simeon Goranov > <[EMAIL PROTECTED]> wrote: > application > models > controllers > views > modules > gallery > models > controllers > views > news > models > controllers > views > public > index.php > > > The questions is - which is the easier way to setup models > autoloading > from all of the modules and application too. The solutions posted on the list do not solve the problem in my oppinion. My thoughts and experiences: You could load the application models by adding the directory to your include_path. If you have e.g. a class User defined in application/models/User.php, a "new User()" will work (autoload) without problems. But it gets tricky if you try to do this with your module's models. Let's say you use a naming scheme for your module modles which adopts the one for module controllers: The index controller class for the gallery module would be Gallery_IndexController (in file modules/gallery/controllers/IndexController.php), so a model class could be Gallery_Image (in file modules/gallery/models/Image.php). But if you try "new Gallery_Image()" this will fail because Zend_Load tries to load gallery/image.php and searches the include_path for this. For this structure to work you need your own class loader wich can resolve your modules' modle directory structure and falls back to Zend_Load if you want to load any none model class. Next problem which will accur on cascading operations (update, delete) is that Zend_Db_Table_Abstract uses Zend_Load::loadClass to load dependent table's modle classes, which fails because Zend_Load doesn't know about module model directories. Same problem prevents the use of findManyToManyRowset() magic methods. Maybe I miss something here and somebody has any smart solutions which might be shared. Regards -joachim knust
