Symfony FormBuilder中的appendNormTransformer是什么?我什么时候应该使用它而不是appendClientTransformer和prependClientTransformer
答案 0 :(得分: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)
),那么您应该使用appendClientTransformer
或prependClientTransformer
。
相反,如果您想更改规范化数据(从(1)
到(2)
),则应使用appendNormTransformer
或prependNormTransformer
。
因此,规范化转换器位于(1)
和(2)
之间((1)
normalizeTransformer - > (2)
)。客户端转换器位于(2)
和(3)
之间((2)
clientTransformer - > (3)
)
另外,请注意,附加和前置方法([append | prepend] [Norm | Client] Transformer)可能会被添加方法替换(在Symfony 2.1中添加[Norm | Client] Transformer),请参阅{{3}在GitHub上获取更多信息。
希望这有帮助,
马特