Symfony FormBuilder 中的 appendNormTransformer 是什么?我什么时候应该使用它而不是 appendClientTransformer 和 prependClientTransformer
1 回答
3
取自Form.php的类文档块:
To implement your own form fields, you need to have a thorough understanding
of the data flow within a form field. A form field stores its data in three
different representations:
(1) the format required by the form's object
(2) a normalized format for internal processing
(3) the format used for display
A date field, for example, may store a date as "Y-m-d" string (1) in the
object. To facilitate processing in the field, this value is normalized
to a DateTime object (2). In the HTML representation of your form, a
localized string (3) is presented to and modified by the user.
(1)应用程序数据、(2)标准化数据和客户端数据也是如此(3)。
现在,对于您的问题,这取决于要转换哪些数据。如果是您需要转换的客户端数据(从(2)到(3)),那么您应该使用appendClientTransformeror prependClientTransformer。
相反,如果您想更改标准化数据(从(1)到(2)),那么您应该使用appendNormTransformeror prependNormTransformer。
因此,归一化转换器位于(1)和(2)( (1)normalizeTransformer -> (2)) 之间。客户端转换器位于( clientTransformer -> )(2)之间(3)(2)(3)
另外,请注意 append 和 prepend 方法([append|prepend][Norm|Client]Transformer)可能会被 Symfony 2.1 中的 add 方法(add[Norm|Client]Transformer)替换,请参阅GitHub 上的此拉取请求以获取更多信息信息。
希望这会有所帮助,
马特
于 2012-04-20T15:43:47.837 回答