Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

symfony - Description of Symfony2 form events?

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.

Anyone konws exactly when these events are called in the flow?

namespace SymfonyComponentForm;

/**
 * @author Bernhard Schussek <[email protected]>
 */
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';
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are two types of events:

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

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

form.pre_bind DataEvent triggered before data is bound to the form. Triggered by SymfonyComponentFormForm::bind()

form.post_bind DataEvent triggered after data is bound to the form. Triggered by SymfonyComponentFormForm::bind()

form.pre_set_data DataEvent triggered before fields are filled with default data. Triggered by SymfonyComponentFormForm::setData()

form.post_set_data DataEvent triggered after fields are filled with default data. Triggered by SymfonyComponentFormForm::setData()

form.bind_client_data FilterDataEvent triggered before data is bound to the form. Triggered by SymfonyComponentFormForm::bind()

form.bind_norm_data FilterDataEvent triggered after data has been normalized. Triggered by SymfonyComponentFormForm::bind(). See SymfonyComponentFormExtensionCoreEventListenerFixUrlProtocolListener (added by the UrlType for an example)

form.set_data FilterDataEvent triggered while default data is being bound. Triggered by SymfonyComponentFormForm::setData()

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...