Created
March 17, 2011 12:30
-
-
Save beberlei/874244 to your computer and use it in GitHub Desktop.
This Symfony Form Experimental Branch example does not use the DIC.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyFormType extends AbstractFormType | |
{ | |
public function configure(FormBuilder $builder, array $options) | |
{ | |
$builder->setDataClass("MyProject\FooEntity"); | |
$builder->add('my.sub_form'); | |
$builder->add('text', 'name', array('max_length' => 127, 'id' => 'foo')); | |
$builder->add('date', 'created'); | |
$builder->add('choice', 'status', array( | |
'expanded' => true, | |
'multiple' => false, | |
'choices' => array('active' => 'Active', 'inactive' => 'Inactive'), | |
)); | |
$builder->add('repeated', 'password', array('identifier' => 'password')); | |
$builder->add('collection', 'stuff', array( | |
'prototype' => 'my.sub_form', | |
)); | |
} | |
public function getIdentifier() | |
{ | |
return 'my.form'; | |
} | |
} | |
class MySubFormType extends AbstractFormType | |
{ | |
public function configure(FormBuilder $builder, array $options) | |
{ | |
$builder->setDataClass("MyProject\BarEntity"); | |
$builder->add('entity', 'tags', array('class' => 'MyProject\Entity\Tag')); | |
} | |
public function getIdentifier() | |
{ | |
return 'my.sub_form'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Example to use without Symfony Dependency Injection Container */ | |
// with DefaultFormFactory: | |
$factory = DefaultFormFactory::createDefault($validator, "csrfsecret", "storgesecrect", $em); | |
// or complex: | |
$factory = DefaultFormFactory::createInstance(new PhpTheme($templating, "path/to/theme_folder"), $csrfProvider, $validator, $tempStorage, $entityManager); | |
$factory->addType(new MyFormType()); | |
$factory->addType(new MySubFormType()); | |
// Usage | |
$factory->create('my.form'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$factory = DefaultFormFactory::createDefault($validator, "csrfsecret", "storgesecrect", $em); | |
$form = $factory->createType(function($builder) { | |
$builder->add('foo', 'text'); | |
$builder->add('bar', 'datetime'); | |
$builder->add('my.subform'); | |
}); |
I don't see where it is missing. He has an argument without typehint and does not instanciate it.
But you have a typo line 10 of the first file.
seems like the code has changed since i last looked :)
Its just an example i think :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
are you missing a use statement for CsrfProvider ?