Begginner Doubts on Reusability

Hi, I’m currently diving into Yii…I ran into some existential doubts :)

I want to build a page on my web app that should work as a dashboard, or something like that. Basically, I will have 3 distinct parts or widgets (in the visual sense, and not in the Yii framework sense). Each of these widgets, feeds on different database tables, thus different models on my understanding. The thing is that I want to code pieces of code that know how to render those three widgets independently of where they are being used, so that I can reuse them in other places…

So, after reading some things about Widgets(now on the Yii sense), Modules, Actions classes, I’m a bit confused…

The thing I’m looking for is, when on a view, have a widget which knows how to “communicate” with a specific model or controller, and display the information accordingly, [color="#0000FF"]so that when I need to reuse that piece on UI on another page, my only trouble is to include the widget on some view, without touching either models or controllers[/color].

Can someone shed some light here? Where should I look? I think extending CWidget is what I want… am I right?

Thanks in advance!!

André Cardoso

Widgets are usually built to be reusable within a certain context. For example, a ‘recent comments’ widget or a ‘graphing’ widget.

For either case you could build it in such a way that the widget expects data in a certain format. You could then feed that widget data from any model. Look at the blog tutorial for a few examples of how they are used.