Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created March 28, 2011 12:58
Show Gist options
  • Save weaverryan/890407 to your computer and use it in GitHub Desktop.
Save weaverryan/890407 to your computer and use it in GitHub Desktop.
A proposed change to the new form factory's builder creation (to make easier)
<?php
// current
$form = $this->get('form.factory')->create(
new ProductType(),
'my_form',
array('csrf_protection' => false, 'data_class' => 'Acme\StoreBundle\Entity\Product')
);
$product = new Product();
$form->setData($product);
====================
// proposed
$product = new Product();
$form = $this->get('form.factory')->create(
new ProductType(),
'my_form',
array('csrf_protection' => false, 'data' => $product)
);
=====================
// or even!
$product = new Product();
$form = $this->get('form.factory')->create(
new ProductType(),
$product,
array('csrf_protection' => false, 'name' => 'my_form')
);
@mattattui
Copy link

I like the first alternative too - it looks like it'd be compatible with the current method, too (create() would only have to call setData())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment