Yii Framework Forum: Design Question: Separate Or Common Views - Yii Framework Forum

Jump to content

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

Design Question: Separate Or Common Views Rate Topic: -----

#1 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 29 April 2013 - 07:05 AM

I have noticed, that most of my backend views are nearly the same for most or all models used in control panel (backend). Especially for views (actions) like create, update, index, _search and _form. They only differ in fields list (for generic views) or columns definitions (for index views). But header and footer remains nearly the same or the same.

I'm using Twitter Bootstrap quite widely for enhancing my forms, so these footers and headers of forms contain quite a long code (including lot of very similar Javascript code), repeated in most parts. My backend consist of admin module (always enabled) plus one or more other modules, that can be enabled or disabled. Or even removed.

So, what is the best practice in such situation? Keep it following DRY rule and move parts that repeats (with a little bit customization) to admin module as partial views, form which generic views from other modules will share them using renderPartial. Or to keep maximum flexibility, for the price of repeated code.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 773
  • Joined: 02-July 10
  • Location:Central Poland

Posted 30 April 2013 - 02:46 AM

Hi,

if the header and footer are same across views, you could use CContentDecorator widget (http://www.yiiframew...ontentDecorator) and put common parts in separate view used by decorator. As for field definitions I would stick to separate view for every model/action because it is easier to customize them :) Changing that will be also move from scaffolding to model-driven development and I had many bad experience with such approach - there is always someone who says "this field must be next to that one in same line" and model-driven code just does not support such case ;)
red
2

#3 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 01 May 2013 - 04:59 AM

Thanks for a great answer (as always!) :]

No, way -- fields always remain per-view. I don't have that much bad experience as you, but I also see, that this is wrong (dead) path. So I was only asking about form's header and footers.

I haven't got much experience with decorators, so thanks for the tip. I was also thinking about using simple clips here. But the general solution, I'll follow is not a matter of question here. I was asking the design question, so whether to do this or not. Not, how to do this. And it seems, that you support the idea of moving the same or nearly the same parts to common repository and re-use them in separate views.

Thanks and have a great long weekend! :]
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
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