我使用gregwarCaptchaBundle在我的項目,我得到了以下錯誤消息:Could not load type "Symfony\Component\Form\Extension\Core\Type\TextType"
GregwarCaptchaBundle: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');
}
...
}
找不到任何錯誤或錯誤的代碼。神祕的是:我在另一個項目中使用完全相同的代碼。在這個其他項目中,它工作得很好。
什麼版本的Symfony和你使用的捆綁包? – Xatoo
似乎對你正在使用的包正在工作(我假設你使用的是sf3版本)的bundle的sf> = 2.8的支持嘗試指向作曲家json中的dev-master。在github上,我發現sf3兼容性問題尚未結束,但如果您使用sf版本<2.8,則可以嘗試 – Matteo
使用版本1.1 – Matteo