module property to Component class

Couldn’t the “module” property be moved (from CController) to the new “Component” class?

Also: What about having a central topic for small things, like this one?

Why and where?

Currently, only [font="Courier New"]CController[/font] has a [font="Courier New"]getModule[/font] method (which creates a "module" property), pointing to the module it belongs to.

Since a module is an application inside an application, any component (extends [font="Courier New"]CComponent[/font]) can reside in a module.

The proposal is to have a [font="Courier New"]getModule[/font] method in the new [font="Courier New"]Component[/font] class (which will replace the current [font="Courier New"]CComponent[/font] class).

This will help make modules more pluggable/reusable when module’s components need to reference its parent module.

A lesser alternative to having [font="Courier New"]getModule[/font] in [font="Courier New"]Component[/font] is to have it in [font="Courier New"]BaseController[/font] or to add it to [font="Courier New"]Widget[/font].

But how does the component know which module it belongs to? This is simple in the case of controllers, because they are created exclusively by modules, so the module can pass itself as a parameter to the controller’s constructor.

I was thinking about it while writing the original post. I don’t have the answer, but this may be easier the way Yii 2.0 is being designed (which I don’t know) or if considered early enough, can be part of the design itself.

I don’t think it’s possible to do this in both a practical and performant way, also I’m not really sure what benefit it brings. Widgets from one module can be used by another module, so what should getModule() return?

Good points.

When the idea came, it was to have the method return the module the component (a widget in this case) belongs to, not the module that’s using the component. But it might just fit one use case and not fit other ones.