Symfony form.vars.data与form.vars.value [英] Symfony form.vars.data vs form.vars.value

查看:102
本文介绍了Symfony form.vars.data与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.

其中两个变量是valuedata.

因此,假设我们在树枝中有我们的form变量,我们可以使用form.vars.dataform.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.valueform.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆