Derek,

As Benjamin said you can set the transformer in the options like so:

        $field = new ChoiceField('story', array(
            'choices' => $stories,
            'value_transformer' => new
CollectionToChoiceTransformer(array(
                'em' => $em,
                'className' => 'Bundle\ScrumBundle\Entity\Story'
            ))
        ));

However I'm also getting the same error as you. Did you find an
answer?

Leevi

On Nov 4, 3:11 am, Derek ROTH <[email protected]> wrote:
> Thanks for your response.
> I created my own Application\CrexBundle\Form\ProductField class
> extending Symfony\Component\Form\ChoiceField to get around the
> "protected" problem.
>
> But I am facing another problem now; my entity is: Application
> \CrexBundle\Entity\Product
>
> And the code in my ProductField class is:
>
>                 $collectionToChoiceTransformer = new 
> \Symfony\Bundle\DoctrineBundle
> \Form\ValueTransformer\CollectionToChoiceTransformer(array(
>                     'em' => $em,
>                     'className' => 'Application\CrexBundle\Entity\Product',
>                 ));
>
> Note that I had to write the full path of my class including its
> namespace in the "className" option, even with a "use" statement,
> otherwise I get this: "Warning: class_parents(): Class Product does
> not exist and could not be loaded in /home/droth/workspace/C-rex/src/
> vendor/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php line
> 224".
>
> This code generates the followingerror:
> Warning: Invalid argument supplied for foreach() in /home/droth/
> workspace/C-rex/src/vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Form/ValueTransformer/CollectionToChoiceTransformer.php
>  line 76
>
> If I add a leading "\" to my className I get this one:
> Class \Application\CrexBundle\Entity\Product is not a valid entity or
> mapped super class.
>
> So my question is: what is the correct way to use theFormintegration
> of the DoctrineBundle ? Is it usable yet (i know it is far from being
> a final release, I'm just asking if it /should/ work already) ?
> Thanks
>
> Derek
>
> On Oct 29, 4:28 pm, Benjamin Eberlei <[email protected]> wrote:
>
>
>
>
>
>
>
> > the docs and the code went out of sync in that regard, i am not sure how
> > you configure the value transfomer currently but it was a flaw that the
> > setValueTransformer method was public before.
>
> > Fields are Immutable, so there should now be some way to set it via the
> > constructor.
>
> > On Fri, 2010-10-29 at 06:37 -0700, Derek ROTH wrote:
> > > Hi,
> > > I am following the documentation here, using the latest sandbox
> > > (downloaded it today from github):
> > >http://docs.symfony-reloaded.org/master/guides/doctrine/orm/form.html
>
> > > And I get thiserror:
> > >Fatalerror: Call to protected method Symfony\Component\Form
> > > \Field::setValueTransformer()
>
> > > Changing the function to be public solves the problem, but I don't
> > > know if it is the adequate solution.
>
> > > There seems to be a little documentationbug, too. The code in the doc
> > > is:
>
> > > $form->addField($field);
> > > But this method is not defined, I replaced it with:
> > > $form->add($field);
>
> > > But as soon as I add this line, I can only get a blank page, loading
> > > for a while. The field I am trying to add is my only ChoiceField bound
> > > to a Collection ofDoctrineentities, so I think thebugis related to
> > > DoctrineBundle.

-- 
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 developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to