Model Display - Design Question

Hi there,

I’ve got a design question.

I have one controller and some models, for instance Client, Customer, Address.

Throughout the screens I want to display information about those models to the end user.

  1. My initial thought was to put in each model a method display() that would output the content of that model with the appropriate HTML decoration.

in the "main view" I would just do

echo $customer->display();

But then I read there should not be any HTML in a model. So my question is what’s the best design for such a case? I can see:

  1. having a protected/view/model/modelName folder and view files:





and so on

in the "main" views I would call

$this->renderPartial(‘model/client/_display’, array(‘customer’ => $customer));

  1. using widgets




in the "main" views I would call


I know that Gii generates one controller and therefore one view folder for each model but that’s not what I want. I want a number of controllers as minimum as possible.

Thank you


A quick search yielded this this stackoverflow question and the accepted answer seems fair to me. In short the answer says:

  • use renderPartial when all data is already prepared in the current controller

  • use a widget if the data needs to use a separate class and/or is used at many different places on the site

I guess that to a degree personal preference also comes into play.

Thanks Jodev,

I think in my case it’s better to use renderPartial