3
votes

I need to create a form class,I'm following the symfony book in http://symfony.com/doc/current/book/forms.html

I am trying to create a form in src/Acme/TaskBundle/Form/Type/TaskType.php, but when I look at the folder structure on my project there is no "Form" folder.

I try to create the Form folder manually, in src/Acme/TaskBundle/, I get an error in the the Form Folder and in the TaskType.php files ( namespace Acme\TaskBundle\Form\Type Expected:Identifier).

Is there a way to create the Form folder in an automatic way? Or how can I create in manually?

3
Show the full code. There's no generator for forms.meze
Ok, I was able to create it manually. Thanks!Daniel

3 Answers

4
votes

The Form folder is just a convention — you can put your forms wherever you want. The convention extends to:

  • Form\Type for form types,
  • Form\Model for form models,
  • Form\Handler for form handlers,
  • etc.
1
votes

Have you tried the command, might be what you're looking for

php app/console generate:doctrine:form 
0
votes

I just created it manually. form: (my case: LL\NameBundle\Form)

FormName.php

<?php

namespace LL\NameBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class FormName extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('add')
            ->add('your')
            ->add('fields')
        ;
    }

    public function getName()
    {
        return 'form-name';
    }
}

Controller:

use LL\NameBundle\Form\FormName;

public function()
{
    $form = new FormName();
    $form = $this->form( $form, $entity );

    return array(
       'form' => $form->createView()
    );
}

This Works for me, if it doesn't work please post some code.