0

我有一个具有很多属性的模型和一个控制器,但我也有近 100 个模板。此模板中大约 90% 的字段和视图是相同的。用户可以填写任何模板,保存并根据需要将其打印为 PDF。实现这种关系的最佳方法是什么?我只看到一种方式:1. 1 个模型,100 个控制器(因为所有模板都必须具有所有 REST 操作)和包含的模块,所有模块都具有相同的操作,以及 100 个用于表单和视图的共享部分。

理想情况下,当然,每个模板 1 个模型、1 个控制器,但这不是 DRY 的方式。

我错了吗?还有另一种简单的方法,一个模型、一个控制器和 100 个部分?将不胜感激任何建议。

4

1 回答 1

0

This is a solution that could be implemented provided your scenario is simple. (I am giving this because you have not mentioned anything about the so called templates and types of fields).

Anyway, have one controller and one model (Because you say 90% fields are same. Having 10% nulls aint a big deal). Then create a form with all these fields organized as templates. Have a select box to select the template and based on that hide or show your fields with JavaScript.

Assuming you have a field to indicate template_type in your model you wont be having any problem saving this and displaying. Or even switching templates by editing your model.

于 2013-08-27T02:21:27.010 回答