未定义的方法' getArticulos'。方法名称必须以findBy或findOneBy

时间:2018-05-16 16:29:32

标签: symfony

未定义的方法' getArticulos'。方法名称必须以findBy或findOneBy开头! 500内部服务器错误 - BadMethodCallException 堆栈跟踪

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  +

日志 - 1错误

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".

说错误出现在第24行的ProductosController.php中,但我无法看到它:

class ProductosController扩展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));
}

}

有什么想法吗?感谢

1 个答案:

答案 0 :(得分:0)

我在listarAction中看到的是你有这个:

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

它应该是这样的:

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

希望有所帮助