GregwarCaptchaBundle:无法加载TextType

时间:2015-12-10 14:11:57

标签: php symfony captcha

我在我的项目中使用gregwarCaptchaBundle并收到以下错误消息:Could not load type "Symfony\Component\Form\Extension\Core\Type\TextType"

详细信息:

 at FormRegistry ->getType ('Symfony\Component\Form\Extension\Core\Type\TextType')
in vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php at line 121  +
at FormRegistry ->resolveAndAddType (object(CaptchaType))
in vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php at line 86  +
at FormRegistry ->getType ('captcha')
in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 82  +
at FormFactory ->createNamedBuilder ('captcha', 'captcha', null, array('distortion' => false, 'reload' => true, 'as_url' => true, 'humanity' => '1000'))
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 106  +
at FormBuilder ->create ('captcha', 'captcha', array('distortion' => false, 'reload' => true, 'as_url' => true, 'humanity' => '1000'))
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 267  +
at FormBuilder ->resolveChildren ()
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 215  +
at FormBuilder ->getForm ()
in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 39  +
at FormFactory ->create (object(RatingForm), null, array())
in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 250  +
at Controller ->createForm (object(RatingForm))
in vendor/xxBundle/RatingBundle/pp/RatingBundle/Controller/DefaultController.php at line 63  +
at DefaultController ->renderRatingInterfaceAction (object(Request), 'Profil', '3209', true, false, true, '5')
    ...

formtype的代码是:

<?php


    ...

    public function setUser($user) {
        $this->user = $user;
    }

    public function setSession($session) {
        if (!is_null($session)) {
            $sessionBlocked = $session->get(sprintf('gcb_%s', 'captcha') . '_humanity');
            $this->sessionBlocked = $sessionBlocked;
        }
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        //$user = $builder->getData()->getUser();

        $builder->setMethod('post');
        $builder->setAction('');
        $builder->add('commenctcontent', 'textarea', array(
            'required' => true,
        ))
        ->add('name','text',array(
            'required' => true,
        ))
        ->add('email','text',array(
            'required' => true,
        ));

        if(!is_object($this->user)){
            $options = array(
                'distortion'    => false,
                'reload'        => true,
                'as_url'        => true,
                'humanity'      => 1000,
            );
            $builder->add('captcha', 'captcha', $options);
        }

        $builder->add('starratevalue','hidden');

    }
    ...
}

无法找到任何错误或错误的代码。神秘的是:我在另一个项目中使用完全相同的代码。在这个其他项目中,它的工作非常好。

2 个答案:

答案 0 :(得分:3)

GregwarCaptchaBundle正在尝试通过其完全限定的类名加载验证码表单类型的基本类型。这是Symfony 2.8中添加的一项功能,是3.0中的默认功能。使用this commit,捆绑包与Symfony 3.0兼容,但Symfony 2.7不兼容。使用版本v1.0.12而不是版本v1.0.13应该可以解决问题。

捆绑的问题队列中的

编辑: Following some discussion。作者删除了v.1.0.13标记并添加了v2.0标记。新的兼容性信息指出:

  • 如果您正在使用Symfony&lt; 2.8或PHP&lt; 5.5,你应该使用版本1。*
  • 如果您使用的是Symfony&gt; = 2.8且PHP&gt; = 5.5,则应使用版本2. *

答案 1 :(得分:0)

我刚刚升级到symfony版本2.8,它的工作原理! :)