0
votes

Undefined method 'getArticulos'. The method name must start with either findBy or findOneBy! 500 Internal Server Error - BadMethodCallException Stack Trace

in vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php at line 226  -
                    break;
                default:
                    throw new \BadMethodCallException(
                        "Undefined method '$method'. The method name must start with ".
                        "either findBy or findOneBy!"
                    );
at EntityRepository ->__call ('getArticulos', array())
in src\AppBundle\Controller\ProductosController.php at line 24  +
at ProductosController ->listarAction (object(Request))
at call_user_func_array (array(object(ProductosController), 'listarAction'), array(object(Request)))
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 139  +
at HttpKernel ->handleRaw (object(Request), '1')
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 62  +
at HttpKernel ->handle (object(Request), '1', true)
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php at line 169  +
at Kernel ->handle (object(Request))
in web\app_dev.php at line 30  +

Logs - 1 error

INFO - Matched route "productosBEListar".
INFO - Populated the TokenStorage with an anonymous Token.
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Knp\Bundle\PaginatorBundle\Subscriber\SlidingPaginationSubscriber::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
CRITICAL - Uncaught PHP Exception BadMethodCallException: "Undefined method 'getArticulos'. The method name must start with either findBy or findOneBy!" at C:\xampp\htdocs\2018\tienda\vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php line 226
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Knp\Bundle\PaginatorBundle\Subscriber\SlidingPaginationSubscriber::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".

Is says the error is in ProductosController.php, on line 24, but i can't see it:

class ProductosController extends Controller {

/**
 * @Route("/", name="homepage")
 */
public function indexAction(Request $request) { {
        return $this->render('AppBundle:Default:productos.html.twig');
    }
}

public function listarAction(Request $request) { {
        $em = $this->getDoctrine()->getManager();
        $articulos = $em->getRepository("BDBundle:Articulos")
                ->getArticulos();

        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
                $articulos, $request->query->getInt('page', 1), 5);

        return $this->render('AppBundle:Default:productos_listar.html.twig', array(
                    'pagination' => $pagination
                        //Mostrar los datos por pantalla, para comprobar si devuelven un valor
                        // var_dump($fabricantes)
        ));
    }
}

public function insertarAction(Request $request) {
    $em = $this->getDoctrine()->getManager();
    $fabricantes = $em->getRepository("BDBundle:Fabricantes")->findAll();
    //libro vacío
    $articulo = new Articulos();
    //le asigno la primera categoria y editorial al libro vacío
    //para evitar ERROR EN LA SELECT
    $fabricante = $em->getRepository("BDBundle:Fabricantes")->find(1);
    $articulo->setCodFabricante($fabricante);

    if ($request->getMethod() == "POST") {
        //0-. Regoger DATOS DEL POST
        //$codArticulo = $request->get('codArticulo');
        // El nombre del get debe ser el mismo que hay en la entidad
        $nombreArticulo = $request->get('articuloArticulos');
        $codArticulo = $request->get('codArticuloArticulos');
        $precioVenta = $request->get('precioVentaArticulos');
        $precioCosto = $request->get('precioCostoArticulos');
        $existencias = $request->get('existenciasArticulos');
        $categoria = $request->get('categoriaArticulos');
        $peso = $request->get('pesoArticulos');
        $logo = $request->get('logoArticulos');

        //RECOGO LOS ID DE LAS FORANEAS
        $codFabricante = $request->get('codFabricanteArticulos');
        //BUSCO LOS OBJETOS RELACIONADOS

        $fabricante = $em->getRepository("BDBundle:Fabricantes")->find($codFabricante);

        $articulo = new Articulos(); //crear un OBJETO --> REGISTRO
        $articulo->setArticulo($nombreArticulo);
        //$articulo->setCodArticulo($codArticulo);
        $articulo->setPrecioVenta($precioVenta);
        $articulo->setPrecioCosto($precioCosto);
        $articulo->setExistencias($existencias);
        $articulo->setCategoria($categoria);
        $articulo->setPeso($peso);
        $articulo->setLogo($logo);

        //$libro->setImagen('symfony.jpg');
        //asignAR LOS OBEJTOS RELACIONADOS
        $articulo->setCodFabricante($fabricante);



        // var_dump($libro);
        //persistir
        $em->persist($articulo);
        //graba
        $flush = $em->flush();
        echo $flush;
    }
    return $this->render('AppBundle:Default:productos_insertar.html.twig', array(
                'fabricantes' => $fabricantes,
                'articulo' => $articulo));
}

public function actualizarAction(Request $request) {

    $codArticulo = $request->get('codArticulo');
    $fabricante = $request->get('codFabricante');
    $em = $this->getDoctrine()->getManager();

    $articulo = $em->getRepository("BDBundle:Articulos")->find($codArticulo);

    $fabricantes = $em->getRepository("BDBundle:Fabricantes")->findAll();

    return $this->render('AppBundle:Default:productos_insertar.html.twig', array(
                'fabricantes' => $fabricantes,
                'articulo' => $articulo));
}

}

Any idea? Thanks

1
$articulos = $em->getRepository("BDBundle:Articulos")->findAll();Cerad
Oh god, thank you so much, it works !Xisco Sánchez

1 Answers

0
votes

What i see is in listarAction you have this:

$articulos = $em->getRepository("BDBundle:Articulos")
            ->getArticulos();

And it should be like this:

$articulos = $em->getRepository("BDBundle:Articulos")
            ->findAll();

Hope it helps