Yii Framework Forum: module property to Component class - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

module property to Component class

#1 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 10 March 2012 - 02:32 AM

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?
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 10 March 2012 - 05:14 AM

Why and where?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 10 March 2012 - 01:17 PM

Currently, only CController has a getModule 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 CComponent) can reside in a module.

The proposal is to have a getModule method in the new Component class (which will replace the current CComponent class).
This will help make modules more pluggable/reusable when module's components need to reference its parent module.

--

A lesser alternative to having getModule in Component is to have it in BaseController or to add it to Widget.
0

#4 User is offline   phpnode 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 18-April 11

Posted 12 March 2012 - 10:26 AM

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.
1

#5 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 12 March 2012 - 03:42 PM

View Postphpnode, on 12 March 2012 - 10:26 AM, said:

But how does the component know which module it belongs to?


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.
0

#6 User is offline   phpnode 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 18-April 11

Posted 12 March 2012 - 05:30 PM

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?
0

#7 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 12 March 2012 - 06:11 PM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users