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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -