Yii Framework Forum: Model Display - Design Question - Yii Framework Forum

Jump to content

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

Model Display - Design Question Rate Topic: -----

#1 User is offline   Renaud 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 04-October 11

Posted 23 February 2013 - 10:04 AM

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:

2) having a protected/view/model/modelName folder and view files:
protected/view/model/client/_display
protected/view/model/client/_displayAll
protected/view/model/customer/_display
protected/view/model/adddress/_display
and so on

in the "main" views I would call

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

3) using widgets

protected/components/widgets/customer_display
protected/components/widgets/customer_displayAll
protected/components/widgets/client_display

in the "main" views I would call

$this->widget('widgets.customer_display',array('customer'=>$customer));


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

#2 User is offline   jodev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 10-January 11
  • Location:The Netherlands

Posted 23 February 2013 - 12:18 PM

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

#3 User is offline   Renaud 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 04-October 11

Posted 23 February 2013 - 12:41 PM

Thanks Jodev,
I think in my case it's better to use renderPartial

Cheers
Renaud
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