抱歉,我是Symfony的初学者,我试图找到答案,但没有任何效果。我正在使用Symfony3.4,它是几个月前从Symfony 2.8更新的。
现在,我正在尝试做一件相当简单的事情:在控制器中使用formType,但无论如何,Symfony不断显示以下错误:无法加载类型"Cha\GeneralBundle\Form\StripePaymentType":类不存在。
这是我的StripePaymentType - 非常非常基本:
namespace ChaGeneralBundleForm;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormFormBuilderInterface;
class StripePaymentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
}
public function getBlockPrefix()
{
return 'cha_stripe_payment_form';
}
}
这是我的控制器操作,再次,一个基本的东西(由于这个奇怪的错误,我什至没有在那里编写任何代码(:
public function upgradeOfferPaymentAction(Offers $offers)
{
$form = $this->createForm(StripePaymentType::class);
return $this->render(
'@ChaGeneral/Offers/offer_payment.html.twig', array(
'form' => $form->createView()
));
}
我尝试将我的表单用作服务,但它也不起作用:
cha.stripe.payment.form:
class: ChaGeneralBundleFormStripePaymentType
tags:
- { name: cha_stripe_payment_form }
我可能错过了一些东西,但我不知道是什么...
提前感谢您的帮助!
您必须在窗体类的顶部添加以下行:
use SymfonyComponentFormExtensionCoreTypeTextType;
还原SF版本不是解决方案,只是回避问题。
好吧,最后我找到了导致这个问题的原因:有人做了一个作曲家更新,我们从Symfony 3.4.13更新到Symfony 3.4.14。一个简单的恢复就可以了,现在一切又恢复了。
非常感谢您的帮助!