symfony - Undefined method 'getDoctrine'. The method name must start with either findBy or findOneBy -
i working symfony2 , getting error message:
undefined method 'getdoctrine'. method name must start either findby or findoneby! 500 internal server error - badmethodcallexception
this entity class:
<?php namespace gestionresiduos\residuobundle\entity; use doctrine\orm\mapping orm; /** * @orm\entity(repositoryclass="residuorepository") */ class bodegacontieneresiduo { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue */ protected $idcontiene; ..... }
this controller's page action method:
<?php namespace gestionresiduos\residuobundle\controller; use symfony\bundle\frameworkbundle\controller\controller; class defaultcontroller extends controller { public function portadaaction() { $em = $this->getdoctrine()->getentitymanager(); $ofertas= $em->getrepository('residuobundle:bodegacontieneresiduo')->findresiduosalmacenados(); return $this->render('residuobundle:default:index.html.twig'); } }
this entityrepository:
<?php namespace gestionresiduos\residuobundle\entity; use doctrine\orm\entityrepository; class residuorepository extends entityrepository { public function findresiduosalmacenados() { $em = $this->getdoctrine()->getentitymanager(); $consulta = $em->createquery('select r residuobundle:bodegacontieneresiduo'); return $consulta->getoneornullresult(); } }
i tried solutions in post scorpion , post k-alex
so, problem ???
in repository class, instead of:
$em = $this->getdoctrine()->getentitymanager();
you should use:
$em = $this->getentitymanager();
reference:
http://www.doctrine-project.org/api/orm/2.2/class-doctrine.orm.entityrepository.html
Comments
Post a Comment