我收到此错误:
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 form clase,因此它可以重复使用,并且我已经关注the manual。
我在Windows中使用symfony 2.3.4和XAMPP
我已经尝试清除两个环境中的缓存,重启apache和MariaDB,你有什么线索吗?非常感谢你!
我已经为其他形式完成了其他类型,并且它完美运行,所以我认为某些地方有些错误,但与命名空间无关。
这是我的控制器,它位于文件夹\ src \ DBP \ InterfazIcedbpBundle \ 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 \ InterfazIcedbpBundle \ 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';
}
}
答案 0 :(得分:1)
尝试将此添加到您的控制器:
use DBP\InterfazIcedbpBundle\Form\Type\PreferencesIcecatType;
错误说无法找到你的表单类,所以说它在哪里。
答案 1 :(得分:0)
可能存在拼写错误。在控制器中使用时,FormType文件的名称,FormType类的名称。检查命名空间。