-- jasonzfw <[email protected]> wrote
(on Tuesday, 01 September 2009, 10:15 AM -0700):
> Which brings me to my question. Surely there's a way to use models found in
> the Default module within other modules such as an Admin module? Otherwise
> the only alternative seems to be copying and renaming models into the Admin
> module's model directory?

Absolutely.

Simply make sure you've setup a resource autoloader for the default
module. There are two ways to do this:

 * In your default module's bootstrap, initialize an autoloader:
 
       protected function _initDefaultAutoloader()
       {
           $al = new Zend_Application_Module_Autoloader(array(
               'namespace' => 'Default', // or 'App', or whatever
               'basePath'  => dirname(__FILE__),
           ));
           return $al;
       }

 * As of 1.9.2, you can segregate your default module from your
   application path, and load its bootstrap separately. For example,
   with the following tree:

     application/
     |-- Bootstrap.php
     |-- configs/
     |-- modules/
     |   |-- default/
     |   |   |-- Bootstrap.php

   application/modules/default/Bootstrap.php would contain the class
   Default_Bootstrap extending Zend_Application_Module_Bootstrap. In
   this case, the autoloader initialization is already done, using the
   namespace 'Default'.

Once autoloading is complete, if your models are in the appropriate
directory and named correctly:

    models/
        Foo.php - Default_Model_Foo

then you can simply instantiate them and use them:

    $foo = new Default_Model_Foo();

and not need to worry in your code about where they come from.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to