Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Model Display - Design Question

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

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>