您可以做的替代方案是创建一个表单生成器对象可以扩展的类,该类为适当类型的 HTML 元素提供一些通用功能/属性。显然,如果不了解您想要做什么以及如何做的更大蓝图,我什至无法开始告诉您如何将其纳入您自己的策略中。
I think that this could be a good approach if you're wanting to also tie your input objects in with something else. Like say, a validation/message response where your validation object passes data off to your input helper. This should allow an 'easy' way to provide some user functionality in your forms.
If you aren't looking to incorporate some other functionality into this class at some point and you just want to spit out some HTML, and are worried about performance, you should just type it out raw.
A suggestion
With your current strategy you're gonna wind up copying a lot of things over and over. When you want to create a password input or a textarea you'll wind up copying a lot of these same variables!
What you could do as an alternative is create a class that your form generator objects can extend from that provide some general functionality/properties for the appropriate types of HTML elements. Obviously I couldn't even begin to tell you how to incorporate this into your own strategy without knowing a bigger picture of what you're trying to do and how you're trying to do it.
发布评论
评论(1)
我认为如果您还想将输入对象与其他对象绑定在一起,这可能是一个好方法。就像验证/消息响应一样,验证对象将数据传递给输入助手。这应该允许以“简单”的方式在表单中提供一些用户功能。
如果您不希望在某个时候将一些其他功能合并到此类中,并且您只想输出一些 HTML,并且担心性能,那么您应该直接将其键入。
建议
按照你目前的策略,你最终会一遍又一遍地复制很多东西。当您想要创建
password
输入或textarea
时,您最终会复制大量相同的变量!您可以做的替代方案是创建一个表单生成器对象可以扩展的类,该类为适当类型的 HTML 元素提供一些通用功能/属性。显然,如果不了解您想要做什么以及如何做的更大蓝图,我什至无法开始告诉您如何将其纳入您自己的策略中。
I think that this could be a good approach if you're wanting to also tie your input objects in with something else. Like say, a validation/message response where your validation object passes data off to your input helper. This should allow an 'easy' way to provide some user functionality in your forms.
If you aren't looking to incorporate some other functionality into this class at some point and you just want to spit out some HTML, and are worried about performance, you should just type it out raw.
A suggestion
With your current strategy you're gonna wind up copying a lot of things over and over. When you want to create a
password
input or atextarea
you'll wind up copying a lot of these same variables!What you could do as an alternative is create a class that your form generator objects can extend from that provide some general functionality/properties for the appropriate types of HTML elements. Obviously I couldn't even begin to tell you how to incorporate this into your own strategy without knowing a bigger picture of what you're trying to do and how you're trying to do it.