Symfony form.vars.data与form.vars.value [英] Symfony form.vars.data vs form.vars.value
问题描述
Symfony中的FormView对象包含多个变量,可以使用公共vars
属性通过细枝访问.
A FormView object in Symfony contains several variables, that can be accessed via twig using the public vars
property.
其中两个变量是value
和data
.
因此,假设我们在树枝中有我们的form
变量,我们可以使用form.vars.data
和form.vars.value
来访问它们.
So, supposing that we have our form
variable in twig, we can access them using form.vars.data
and form.vars.value
.
文档很清楚这些属性的含义:
The documentation is clear about the meaning of those properties:
-
值:呈现时将使用的值(通常为HTML属性value).
value: The value that will be used when rendering (commonly the value HTML attribute).
数据:该类型的规范化数据.
data: The normalized data of the type.
但是当我使用{{ dump(form.vars) }}
并比较form.vars.value
和form.vars.data
时,它们看起来一样.为什么?这两个属性的正确含义和正确用法是什么?
but when I use {{ dump(form.vars) }}
and compare form.vars.value
and form.vars.data
they look like identical. Why? What's the correct meaning and proper usage of those two properties?
推荐答案
以DateType字段为例.
Take for example a DateType field.
在这里,value
类似于字符串2016-06-10
.
另一方面,data
将是对应的DateTime
-Object.
Here, value
would be something like the string 2016-06-10
.
data
on the other hand would be a corresponding DateTime
-Object.
使用文本"字段时,您不会看到任何区别,因为在两种情况下,都只会有一个字符串.
When using Text fields, you will not see any difference because in both cases there will be just a string.
这篇关于Symfony form.vars.data与form.vars.value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!