简体   繁体   中英

'Is the "data_class" form option set correctly?' Yes. Yes, it is

I am attempting to use a data transfer object with a Symfony form. The form type I'm using looks like this:

class SuggestedEventPricingFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $localCurrency = $builder->getData()->getCurrencyCode();
        $builder
            ->add('pricingScheme', TextType::class, ['required' => true])
            ->add(
                'eventPricing',
                EventPricingFormType::class,
                ['error_bubbling' => false, 'local_currency' => $localCurrency]
            )
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults(['data_class' => SuggestedEventPricing::class]);
    }
}

... and when I command-click on SuggestedEventPricing in PHPStorm, I am correctly taken to the class definition, so I know my use statement in the form type is correct.

But I still get this message when trying to load the form:

Class "AppBundle\Value\SuggestedEventPricing" not found. Is the "data_class" form option set correctly?

Any ideas for next steps I can take in debugging this?

Well, today I learned something: PHPStorm will happily sent you to a file that has the wrong namespace declared at the top of it.

Changing the namespace at the top of the class file I wanted to use (along with the reference in the use statement at the top of my form type) fixed this up quickly. I hope this helps someone else. (Greetings, future Googler!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM