Re: [symfony-users] Symfony2 Form as a Standalone component

2011-12-22 Thread Hristo Salabashev
Hi Hari,

you can check how is it done in Silex:

https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/FormServiceProvider.php

The controller method createFormBuilder translates to

public function createFormBuilder($data = null, array $options = array())
{
return $this->container->get('form.factory')->createBuilder('form',
$data, $options);
}


I guess you will also need to handle form binding yourself as you wont have
the right Request object.

public function bindRequest(Request $request)
{
// Store the bound data in case of a post request
switch ($request->getMethod()) {
case 'POST':
case 'PUT':
$data = array_replace_recursive(
$request->request->get($this->getName(), array()),
$request->files->get($this->getName(), array())
);
break;
case 'GET':
$data = $request->query->get($this->getName(), array());
break;
default:
throw new FormException(sprintf('The request method
"%s" is not supported', $request->getMethod()));
}

return $this->bind($data);
}


Hope that helps
Cheers

On Thu, Dec 1, 2011 at 8:36 PM, Hari K T  wrote:

> Hi Guys ,
>
> I downloaded the Symfony2 Form components .
> I was looking how to create the form object .
> Is it the FormFactory , FormBuilder or anything else ?
>
> I looked the book
>
>
> http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes
>
> But its mainly on the Symfony controller .
>
> I guess I want to pass the Event Dispatcher Object , Validator Object etc
> to the Form object when creation 
>
> But I am not sure where the entry point to the form is ..
>
> Wondering , so if someone can show me the right path , it may help me to
> go easily .
>
> Thanks
>
> --
> 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 users" group.
> To post to this group, send email to symfony-users@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-users+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>

-- 
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 users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en


[symfony-users] Re: form from self-referencing object won't build

2011-06-20 Thread Hristo Salabashev
Hi Bart,

having `children` the same type as the parent starts an endless
recursion ( children like create another children which will create
another and so on ).
Easiest way to address this (tho maybe not optimal) is to create
another definition for the nested type.

On Jun 17, 9:02 am, Bart  wrote:
> Hi everyone.
>
> I'm having a rather odd problem which I suspect is either a bug or
> more likely I'm trying to do things the wrong way.I'd appreciate if
> you can shed a little light on the proper way to address this. Let me
> describe the issue.
>
> We have a container with the following ORM definition:
> Container:
>  type: entity
>  table: container
>  id:
>    id:
>      type: integer
>      generator:
>        strategy: AUTO
>    fields:
>      name:
>        type: string
>        length: 25
>    oneToMany:
>      children:
>        targetEntity: Container
>        mappedBy: parent
>   manyToOne:
>     parent:
>       targetEntity: Container
>       inversedBy: children
>      joinColumn:
>         name: parent_id
>         referencedColumnName: id
>
> And a FormType which looks as follows:
> use
>    Symfony\Component\Form\AbstractType,
>    Symfony\Component\Form\FormBuilder
>    ;
>
> class ContainerType extends AbstractType
> {
>    public function buildForm(FormBuilder $builder, array $options)
>    {
>        $builder
>            ->add('name', 'text')
>            ->add('children', 'collection', array(
>                'type' => new ContainerType(),
>                'prototype' => false,
>                'allow_add' => true,
>                'allow_delete' => true, ));
>
>    }
>
> }
>
> In the Controller we create a formBuilder by:
>                $data = new Container();
>                $form = $this->get('form.factory')->create(new
> ContainerType());
>                $form->setData($data);
> etc...
>
> The form will crash with a:
> 'Fatal error: Maximum function nesting level of '100' reached,
> aborting! in /app/cache/dev/twig/15/ff/
> 401ed143a10a78a26e39b6e98c03.php on line 38'
> And a long stack trace showing the form recursing on itself.
>
> I looked at the code and I didn't see an easy way to stop the
> Container from rendering an infinite depth. What I'd really want is
> for it to throw out all the existing children from a parent but when a
> child does not exist not to create a prototype one
>
> Obviously the buildForm method calls "new ContainerType" so that would
> be at the root of the issue. However I can't seem to pass
> "\ContainerType" as type.
>
> Can anyone shed a light on the correct way to do this?
>
> Thanks!

-- 
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 users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en