In the book, there is the following example:
[code]
namespace Acme\StoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Acme\StoreBundle\Entity\Product;

class DefaultController extends Controller
{
    public function indexAction()
    {
        // create a product and give it some dummy data for this example
        $product = new Product();
        $product->name = 'Test product';
        $product->setPrice('50.00');

        $form = $this->get('form.factory')
            ->createBuilder('form', $product)
            ->add('name', 'text')
            ->add('price', 'money', array('currency' => 'USD'))
            ->getForm();

        return $this->render('AcmeStoreBundle:Default:index.html.twig', 
array(
            'form' => $form->createView(),
        ));
    }
}[/code]

Then, it states that you can use a type class, like this:

[code]// src/Acme/StoreBundle/Form/ProductType.php

namespace Acme\StoreBundle\Form;

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

class ProductType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('name');
        $builder->add('price', 'money', array('currency' => 'USD'));
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'Acme\StoreBundle\Entity\Product',
        );
    }
}[/code]

And in the controller:

[code]// src/Acme/StoreBundle/Controller/DefaultController.php

// add this new use statement at the top of the class
use Acme\StoreBundle\Form\ProductType;

public function indexAction()
{
    $form = $this->get('form.factory')->create(new ProductType());

    // ...
}[/code]

The only problem is I can't get a refrence to $product in the controller 
when using ProductType. This means I can't get the form data and persist the 
object to the database.

How would I go about doing this?

-- 
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

Reply via email to