找不到Symfony2表单类型类

找不到Symfony2表单类型类,symfony,Symfony,我得到这个错误: Fatal error: Class 'DBP\InterfazIcedbpBundle\Form\Type\PreferencesIcecatType' not found in C:\xampp\htdocs\InterfaceICEDBP\src\DBP\InterfazIcedbpBundle\Controller\PreferencesIcecatController.php on line 66 我正在尝试创建e表单clase,这样它就可以重用,我也遵循了这一点

我得到这个错误:

Fatal error: Class 'DBP\InterfazIcedbpBundle\Form\Type\PreferencesIcecatType' not found in C:\xampp\htdocs\InterfaceICEDBP\src\DBP\InterfazIcedbpBundle\Controller\PreferencesIcecatController.php on line 66
我正在尝试创建e表单clase,这样它就可以重用,我也遵循了这一点

我正在使用symfony 2.3.4,在带有XAMPP的Windows中

我已经尝试在这两种环境中清除缓存,重新启动apache和MariaDB,你有什么线索吗?多谢各位

我已经为我拥有的其他表单做了其他类型的工作,它工作得非常完美,所以我认为在某些地方有问题,但与名称空间无关

这是我的控制器,它位于文件夹\src\DBP\interfazicedbbundle\Controller中

namespace DBP\InterfazIcedbpBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use DBP\InterfazIcedbpBundle\Entity\Preicedbp\category;
use DBP\InterfazIcedbpBundle\Entity\Preicedbp\supplier;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Mapping as ORM;

use DBP\InterfazIcedbpBundle\Form\Type\PreferencesIcecatType;



class PreferencesIcecatController extends Controller
{
    public function indexAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        $categories = $em->getRepository('DBPInterfazIcedbpBundle:Preicedbp\Category')->getAllCategories();
        $categories = $em->getRepository('DBPInterfazIcedbpBundle:Preicedbp\Category')->getCategoriesJSON($categories);

        $suppliers = $em->getRepository('DBPInterfazIcedbpBundle:Preicedbp\Supplier')->getAllSuppliers();

        $distributors = $em->getRepository('DBPInterfazIcedbpBundle:Preicedbp\Distributor')->getAllDistributors();
        $distributors = $em->getRepository('DBPInterfazIcedbpBundle:Preicedbp\Distributor')->getDistributorsJSON($distributors);

        $query = $em->createQuery(
                'SELECT c.catId FROM DBPInterfazIcedbpBundle:Preicedbp\ImpCategories c WHERE c.idImpPreferences=1
                ORDER BY c.catId ASC');

        $_selected = $query->getResult();
        $categories_selected = "";
        foreach($_selected  as $cat) {
            $categories_selected .= $cat['catId'].",";
        }
        //$categories_selected = $em->getRepository('DBPInterfazIcedbpBundle:Category')->getCategoriesSelectedJSON($categories_selected);

        $query = $em->createQuery(
                'SELECT c.distributorId FROM DBPInterfazIcedbpBundle:Preicedbp\ImpDistributors c WHERE c.idImpPreferences=1
                ORDER BY c.distributorId ASC');

        $_selected = $query->getResult();
        $distributors_selected = "";
        foreach($_selected  as $dist) {
            $distributors_selected .= $dist['distributorId'].",";
        }

        $query = $em->createQuery(
                'SELECT c.supplierId FROM DBPInterfazIcedbpBundle:Preicedbp\ImpSuppliers c WHERE c.idImpPreferences=1
                ORDER BY c.supplierId ASC');

        $_selected = $query->getResult();
        $suppliers_selected = "";
        foreach($_selected  as $sup) {
            $suppliers_selected .= $sup['supplierId'].",";
        }

        $preferences = $this->getDoctrine()->getRepository('DBPInterfazIcedbpBundle:Preicedbp\ImpPreferences')->find(1);

        $pref_id = $preferences->getId();

        $options = array('suppliers_selected'=>$suppliers_selected, 'id'=>$pref_id);
        $form = $this->createForm(new PreferencesIcecatType(),$options);

        if ($request->isMethod('POST')) {
            //Obtenemos los datos del formulario
            $form->bind($request);
            $datos = $form->getData();

            $datos->setTypeUpdate(1);
            //Guardamos imp_preferences automáticamente
            $em->persist($datos);
            $em->flush();

            //Recogemos las categorias, suppliers y dist que se guardan a parte
            $cat_selected = $form["cat_selected"]->getData();
            $sup_selected = $form["sup_selected"]->getData();
            $dist_selected = $form["dist_selected"]->getData();


            //Primero borramos lo que hay para luego insertarlo de nuevo (así me olvido de mirar si está ya insertado o no).
            $query = $em->createQuery('DELETE FROM DBPInterfazIcedbpBundle:Preicedbp\ImpSuppliers c WHERE c.idImpPreferences='.$pref_id);
            $query->getResult();

            $query = $em->createQuery('DELETE FROM DBPInterfazIcedbpBundle:Preicedbp\ImpDistributors c WHERE c.idImpPreferences='.$pref_id);
            $query->getResult();

            $query = $em->createQuery('DELETE FROM DBPInterfazIcedbpBundle:Preicedbp\ImpCategories c WHERE c.idImpPreferences='.$pref_id);
            $query->getResult();

            $categorias = explode(",",$cat_selected);
            foreach($categorias as $cat) {
                if(empty($cat)) continue;
                $conn = $em->getConnection();
                $query = "INSERT INTO imp_categories VALUES($pref_id,$cat)";
                $stmt = $conn->prepare($query);
                $stmt->execute(array());
            }

            $fabricantes = explode(",",$sup_selected);
            foreach($fabricantes as $sup) {
                if(empty($sup)) continue;
                $conn = $em->getConnection();
                $query = "INSERT INTO imp_suppliers VALUES($pref_id,$sup)";
                $stmt = $conn->prepare($query);
                $stmt->execute(array());
            }

            $distribuidores = explode(",",$dist_selected);
            foreach($distribuidores as $dist) {
                if(empty($dist)) continue;
                $conn = $em->getConnection();
                $query = "INSERT INTO imp_distributors VALUES($pref_id,$dist)";
                $stmt = $conn->prepare($query);
                $stmt->execute(array());
            }




            $this->get('session')->getFlashBag()->add('notice', 'La configuración se ha guardado con éxito!!');
        }

        //Aquí vuelvo a sacar las categorias seleccionadas porque al cambiar tengo que volver a sacarlas.

        //$em = $this->getDoctrine()->getEntityManager();

        $query = $em->createQuery(
                'SELECT c.catId FROM DBPInterfazIcedbpBundle:Preicedbp\ImpCategories c WHERE c.idImpPreferences=1
                ORDER BY c.catId ASC');

        $_selected = $query->getResult();
        $categories_selected = "";
        foreach($_selected  as $cat) {
            $categories_selected .= $cat['catId'].",";
        }
        //$categories_selected = $em->getRepository('DBPInterfazIcedbpBundle:Category')->getCategoriesSelectedJSON($categories_selected);

        $query = $em->createQuery(
                'SELECT c.distributorId FROM DBPInterfazIcedbpBundle:Preicedbp\ImpDistributors c WHERE c.idImpPreferences=1
                ORDER BY c.distributorId ASC');

        $_selected = $query->getResult();
        $distributors_selected = "";
        foreach($_selected  as $dist) {
            $distributors_selected .= $dist['distributorId'].",";
        }

        $query = $em->createQuery(
                'SELECT c.supplierId FROM DBPInterfazIcedbpBundle:Preicedbp\ImpSuppliers c WHERE c.idImpPreferences=1
                ORDER BY c.supplierId ASC');

        $_selected = $query->getResult();
        $suppliers_selected = "";
        foreach($_selected  as $sup) {
            $suppliers_selected .= $sup['supplierId'].",";
        }

        return $this->render('DBPInterfazIcedbpBundle:Preferences:icecat_preicedbp.html.twig', 
                array('categories'=>$categories, 'suppliers'=>$suppliers, 'distributors'=>$distributors,
                        'categories_selected'=>$categories_selected, 'distributors_selected'=>$distributors_selected, 'suppliers_selected'=>$suppliers_selected,
                        'preferences'=>$preferences,'form' => $form->createView()));
    }       

}
这是我在\src\DBP\interfazicedbbundle\Form\Type中的类型

<?php
namespace DBP\InterfazIcedbpBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use DBP\InterfazIcedbpBundle\Form\DataTransformer\StringToArrayTransformer;

class PreferencesIcecatType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $suppliers_selected = $options['suppliers_selected'];
        $pref_id = $options['id'];

        //añadimos las categorias, fabricantes y distribuidores en un campo hidden
        $builder->add('cat_selected', 'hidden', array(
                'data' => '', 'mapped'=>false,
        ));
        $builder->add('sup_selected', 'hidden', array(
                'data' => $suppliers_selected,'mapped'=>false,
        ));
        $builder->add('dist_selected', 'hidden', array(
                'data' => '','mapped'=>false,
        ));


        $builder->add('id', 'hidden', array('data'=>$pref_id,'property_path'=>'id'));
        //$builder->add('id', 'hidden', array());

        //Añadimos el resto de campos
        $builder->add('onMarket', 'choice', array('label'=>'Mercado','choices'   => array(
                '0'   => 'Sólo productos que no estén en el mercado',
                '1' => 'Sólo productos en el mercado',
                '2'   => 'Todos'),'multiple'  => false));

        $builder->add('quality', 'choice', array('label'=>'Calidad','choices'   => array(
                'ICECAT'   => 'ICECAT',
                'SUPPLIER' => 'SUPPLIER',
                'NO-EDITOR'   => 'NO-EDITOR',
                'TODOS'=>'TODOS'),'multiple'  => false));

        $builder->add('importProducts', 'choice', array('label'=>'Filtrar por','choices'   => array(
                '1'   => 'Categorias',
                '2' => 'Fabricantes',
                '3'   => 'Distribuidores',
                '0'=>'TODOS'),'multiple'  => false,'expanded'=>true));

        //$entityManager = $options['em'];
        $transformer = new StringToArrayTransformer($em);
        $builder->add($builder->create('languages', 'choice', array('label'=>'Lenguajes','choices'   => array(
                'ES'   => 'ES',
                'EN' => 'EN',
                ),'multiple'  => true,'expanded'=>false))->addModelTransformer($transformer));

        $builder->add($builder->create('countryMarket', 'choice', array('label'=>'Mercado','choices'   => array(
                'ES'   => 'ES',
                'EN' => 'EN',
        ),'multiple'  => true,'expanded'=>false))->addModelTransformer($transformer));

        $builder->add('onlyUpdateExistings', 'checkbox', array(
                'label'     => 'Actualizar sólo existentes',
                'required'  => false,
        ));

        $builder->add('sel_cat', 'checkbox', array(
                'label'     => 'Seleccionar/Deseleccionar',
                'required'  => false, 'mapped'=>false,
        ));
        $builder->add('sel_sup', 'checkbox', array(
                'label'     => 'Seleccionar/Deseleccionar',
                'required'  => false,'mapped'=>false,
        ));
        $builder->add('sel_dist', 'checkbox', array(
                'label'     => 'Seleccionar/Deseleccionar',
                'required'  => false,'mapped'=>false,
        ));

        $builder->add('show_only_cat', 'checkbox', array(
                'label'     => 'Mostrar sólo seleccionadas',
                'required'  => false,'mapped'=>false,
        ));
        $builder->add('show_only_sup', 'checkbox', array(
                'label'     => 'Mostrar sólo seleccionados',
                'required'  => false,'mapped'=>false,
        ));
        $builder->add('show_only_dist', 'checkbox', array(
                'label'     => 'Mostrar sólo seleccionados',
                'required'  => false,'mapped'=>false,
        ));



        $builder->add('user_icecat', 'text', array( ));
        $builder->add('pass_icecat', 'text', array( ));
        $builder->add('icecat_route', 'text', array( ));
        $builder->add('icecat_subdir', 'text', array( ));
    }

    public function getName()
    {
        return 'preferences_icecat';
    }
}

尝试将此添加到控制器:

use DBP\InterfazIcedbpBundle\Form\Type\PreferencesIcecatType;  

错误是找不到表单类,所以请在它所在的位置说出来

可能是打字错误。在控制器中使用时,输入FormType文件的名称和FormType类的名称。检查名称空间。

它在控制器的第10行。你知道这一点吗?我在使用FormType和MongoDB时遇到了同样的问题。。。。虽然我没有遇到MySQL和FormType类的问题。没有,我没有解决它,抱歉:(这是我在控制器中包含的唯一表单:(总有一天我会尝试再次修复它,当我修复时,我会更新这篇文章。用你的代码再次问你的问题,也许你的问题更简单。我发现了我的问题,我把文件放在了错误的文件夹中。我把它放在了表格中而不是类型中。也许你也这么做了?