Symfony2 表单事件的描述? [英] Description of Symfony2 form events?

查看:28
本文介绍了Symfony2 表单事件的描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自 github 上的 Symfony2 存储库的 FormEvents 类.它链接自主要文章,如何使用表单事件动态生成表单.

This is the FormEvents class from Symfony2 repository on github. It's linked from the main article, How to Dynamically Generate Forms Using Form Events.

有人知道这些事件在流程中的确切调用时间吗?

namespace Symfony\Component\Form;

/**
 * @author Bernhard Schussek <bernhard.schussek@symfony.com>
 */
final class FormEvents
{
    const PRE_BIND = 'form.pre_bind';
    const POST_BIND = 'form.post_bind';
    const PRE_SET_DATA = 'form.pre_set_data';
    const POST_SET_DATA = 'form.post_set_data';
    const BIND_CLIENT_DATA = 'form.bind_client_data';
    const BIND_NORM_DATA = 'form.bind_norm_data';
    const SET_DATA = 'form.set_data';
}

推荐答案

有两种类型的事件:

DataEvent -对表单数据的只读访问.Pre"和Post"事件是只读的.

DataEvent - read-only access to the form data. 'Pre' and 'Post' events are read-only.

FilterDataEvent -允许修改表单数据的事件.

FilterDataEvent - event that allows the form data to be modified.

form.pre_bindDataEvent 在数据绑定到表单之前触发.由 Symfony\Component\Form\Form::bind()

form.pre_bind DataEvent triggered before data is bound to the form. Triggered by Symfony\Component\Form\Form::bind()

form.post_bindDataEvent 数据绑定到表单后触发.由 Symfony\Component\Form\Form::bind()

form.post_bind DataEvent triggered after data is bound to the form. Triggered by Symfony\Component\Form\Form::bind()

form.pre_set_dataDataEvent 在用默认数据填充字段之前触发.由 Symfony\Component\Form\Form::setData()

form.pre_set_data DataEvent triggered before fields are filled with default data. Triggered by Symfony\Component\Form\Form::setData()

form.post_set_dataDataEvent 字段填充默认数据后触发.由 Symfony\Component\Form\Form::setData()

form.post_set_data DataEvent triggered after fields are filled with default data. Triggered by Symfony\Component\Form\Form::setData()

form.bind_client_dataFilterDataEvent 在数据绑定到表单之前触发.由 Symfony\Component\Form\Form::bind()

form.bind_client_data FilterDataEvent triggered before data is bound to the form. Triggered by Symfony\Component\Form\Form::bind()

form.bind_norm_dataFilterDataEvent 在数据标准化后触发.由 Symfony\Component\Form\Form::bind() 触发.参见 Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener(例如由 UrlType 添加)

form.bind_norm_data FilterDataEvent triggered after data has been normalized. Triggered by Symfony\Component\Form\Form::bind(). See Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener (added by the UrlType for an example)

form.set_dataFilterDataEvent 在绑定默认数据时触发.由 Symfony\Component\Form\Form::setData()

form.set_data FilterDataEvent triggered while default data is being bound. Triggered by Symfony\Component\Form\Form::setData()

我建议查看 Form 类本身,以便更好地了解何时触发这些事件以及如何使用它们.

I'd recommend poking around the Form class itself to get a better feel for when these events are triggered, and how you can use them.

这篇关于Symfony2 表单事件的描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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