On 20.01.2011, at 12:58, Bernhard Schussek wrote:
> 2011/1/20 Lukas Kahwe Smith <[email protected]>:
>> Like I said, if I have a form which I want to use with different validation
>> groups I now either have to:
>
> Can you give me an example when you want to use the same form with
> different validation groups? I want to understand the problem better.
>
>> Now if we disallow setting options via setters, then I think we should make
>> that factory service the _only_ way to make form instances. Aka make the
>> constructor protected and provide a form creation service as part of
>> Symfony2 core.
>
> There is one, although I'm still writing the documentation for it:
>
> $form = $this->get('form.factory')->getForm('author', $author);
>
> if you want to use custom validation groups
>
> $form = $this->get('form.factory')
> ->validationGroups('Address')
> ->getForm('author', $author);
>
> or, outside of Symfony2
>
> // you can pass XML and YML file paths to buildDefault()
> $factory = FormFactory::buildDefault();
> $form = $factory
> ->validationGroups('Address')
> ->getForm('author', $author);
So before we had the following:
$form = $this->get('fos_user.form.user');
$form->setValidationGroups(array(Registration));
<service id="fos_user.form.user" class="%fos_user.form.user.class%">
<argument>%fos_user.form.user.name%</argument>
<argument></argument>
<argument type="service" id="validator" />
<argument type="collection">
<argument key="theme">%fos_user.template.theme%</argument>
</argument>
</service>
Now I would want to do the following, notice the setClass() method which sets
the class to use in FormContext::getForm() and setName() which allows me to
just use getForm($data = null) in my code, allowing me to set the name via the
DIC.
$form = $this->get('fos_user.form.user_factory')
->validationGroups(array(Registration)
->getForm();
<service id="fos_user.form.user_factory" factory-service="form_factory"
factory-method="setName" shared="false">
<argument>%fos_user.form.user.name%</argument>
<call method="setClass">
<argument>%fos_user.form.user.class%</argument>
</call>
<call method="setOption">
<argument type="collection">
<argument key="theme">%fos_user.template.theme%</argument>
</argument>
</call>
</service>
Note I am a bit unsure why the setters in the FormFactory() do not have a set
prefix.
regards,
Lukas Kahwe Smith
[email protected]
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en