Design Question: Separate Or Common Views

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.

Hi,

if the header and footer are same across views, you could use CContentDecorator widget (http://www.yiiframework.com/doc/api/1.1/CContentDecorator) 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 ;)

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! :]