Multiple sites, shared modules?

Hello

I’m a newcommer to the world of Yii, but I like it a lot!

I have a question - I’m developing a community portal with separate admin module.

I’ve decided to generate an separate Yii app just for the admin section - can I somehwo tell Yii to use modules stored in another directory (in addition to protected/modules)? Right now I’m just using place-holders with


require(dirname(__FILE__).'/../../../'.MAIN_APP_DIR.'/protected/models/'.basename(__FILE__));

in them and it does work, but not sure if that’s the best / most elegant way to do it.

Or maybe I should stick the admin section back to the main app?

Check this tutorial: http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site

Yes you can put modules in any directory, just pass the complete path on the module definition:




'modules'=>array(

    'admin'=>array(

         'class'=>'application.plugins.news.admin.NewsAdminModule',

         ...

    ),

),



Thanks for your reply. I see I’ve made a misstake in my post title/descriptions. I’m not talking about modules but about models (/application/protected/models)

Yeah, but the modules are stored outside of the application tree - they are stored in another application dir, so “application.plugins” would not be good. Here’s what I’m talking about:




/webroot

    /applicationA

        /protected

            /plugins

                /news

                    /admin


    /applicationB

        /protected

            /plugins



And I need applicationB to access plugins of applicationA

Check setPathOfAlias function. You can do this in your config:


Yii::setPathOfAlias('application2', '/some/path');

Then you can use:


'modules'=>array(

    'admin'=>array(

         'class'=>'application2.plugins.SomeModule',

         ...

    ),

),

Hmm normally I would import aliases:

array(

‘import’=>array(

    'application.plugins.news.components.*',

),

),

but in your case it is outside the application path, don’t know if there’s an alternative for full paths. But this is the path that you should follow.