Module models (preload/import)

Hi there,

When I use a forum module, it would be nice, if i could do something like:

if (forum is enabled) {

Use models from modules.forum.models;

}

I can’t figure out how to do this, it seems that the CWebModule::init() is only run, if a action within the module is called.

Thanks.

I guess that you should use some options.

Did you tried to use like this:


if(Yii::app()->params['forumEnabled']){}

Think I got it now:


Yii::app()->getModule('community');

or


Yii::app()->getModule('community')->getModule('forum');

If forum is a submodule to community.


Yii::app()->hasModule('community');

returns true if the module is installed.

Hi

I don’t quite understand the difference preload and import around modules

I was testing an internationalisation module which I declared

it was based on a component

it wasn’t working untill I preloaded the needed component

could someone please shed some light on the differences in the loading process of modules , preload , import ?

Thanks

Modules are independant, they add funcionality to the application, but the application should not depend on them, say a users module, adds the posibility to manage users, login, etc. but the application could run wihtout it.

When you preload something it gets (always) automatically imported when creating the application.

But you can use import, when you need a class that will be only used in certain cases:

Say you have a class that inherits from another,

class A extends B{}

if B is not preimported then you need to import it before use it.

Yii::import(‘path.to.B’);

class A extends B{}