Organizing portlets...

Basically I am planning to only have 1 page controller… all the rest will be inside portlets, like a main view for articles, side view for latest comments etc etc…

So all other controllers will act like modules… the only thing I don't really like with portlets is that they don't have actions so they will be in seperate files… but something like articles, will probably have index, latest articles, highest rated articles etc…

Does anybody have any idea how to ogranize this the best way… or can I reuse the actions in the controller in a widget / portlet ?

Hi.

Though I am not fully sure about the point you do not like portlets, in terms of Calendar widget that I have made, actions that are defined in the post controller are called from the component view of the widget. Since the calendar widget may show posts(articles) and it is natural to define those actions in PostController. Please check the code out.

  • protected/components/Calendar.php
  • protected/components/views/calendar.php
  • protected/controllers/PostController.php
  • protected/models/Post.php

My basic idea is that the actions are all related to a model and a controller, not to a widget in this case. In another words, a widget is only a UI (it may be different when you want to make a UserManagement widget or something like that though). In this case, you want to process articles(posts). Then all of the actions should be stored in the controllers/PostController and all the helper functions should be stored in the models/Post as follows.

Portlet view (V) -> Post controller action © -> Post model (M)

                <-                            <-

In this case, this kind of widget should not be a module that has its own models and controllers, I think.

Ah ok… so i can access controller actions inside components? It is not that I don’t like widgets… actually I haven’t used YII at all just curious about switching from Cake :)

The only thing that I was curious about is if i can access functions from the controller… with cake can only do this with requestaction… which uses allot of overhead… the problem is kind of that allot of "portlets", "widgets", "blocks" or whatever name you want to give them… can be related to one controller as an example Articles… and these can have logic inside them, so not only to retrieve data from model…

I basically see every block on the page as a view, with controller and model… which are controlled by one "super" controller the page controller.

Ill have a look at that code… but it’s seems an entire blog, kinda lazy diggin through it all  ;D

Quote

Ah ok.. so i can access controller actions inside components? It is not that I don't like widgets... actually I haven't used YII at all just curious about switching from Cake :)

Even though this question seems to be quite natural for me, it is allowed in Yii. Please check this discussion.

Quote

Quote

Do you think it is fine as well to change the view in the components? It may work but I do not know it is recommended or not according to the 'Yii style' if it exists.

I think it’s fine. ;)

There's no strict rule for this.

Quote

The only thing that I was curious about is if i can access functions from the controller... with cake can only do this with requestaction.. which uses allot of overhead.. the problem is kind of that allot of "portlets", "widgets", "blocks" or whatever name you want to give them... can be related to one controller as an example Articles... and these can have logic inside them, so not only to retrieve data from model...

May be Qiang replies better, but I think the static method does not carry heavy load.

Quote

I basically see every block on the page as a view, with controller and model.. which are controlled by one "super" controller the page controller.

This idea seems to be theoretically right. But I prefer the idea that there are many widgets that can take care of each UI and share common actions in a controller and common access methods in a AR/model.

Quote

Ill have a look at that code.. but it's seems an entire blog, kinda lazy diggin through it all  ;D

You do not have to read through, checking one widget (e.g. calendar) related code is enough.

P.S. A widget (portlet) idea has a limited usage. there should be a module that has more complex functionality, thus it needs to have its own MVC as you described previously.

;D Ah I think somebody had the same idea as me…

http://www.yiiframew…17.html#msg7117