В настоящее время я работаю с Symfony2, и я получаю это сообщение об ошибке:Неопределенный метод 'getDoctrine'. Имя метода должно начинаться с findBy или findOneBy
Неопределенный метод 'getDoctrine'. Имя метода должно начинаться с findBy или findOneBy! 500 Внутренняя ошибка сервера - BadMethodCallException
Это мой Entity Класс:
<?php
namespace Gestionresiduos\ResiduoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="ResiduoRepository")
*/
class BodegaContieneResiduo
{
/**
* @ORM\Id
* @ORM\column(type="integer")
* @ORM\GeneratedValue
*/
protected $idContiene;
.....
}
Это метод страницы Действие Контролера:
<?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');
}
}
Это мой 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 FROM ResiduoBundle:BodegaContieneResiduo');
return $consulta->getOneOrNullResult();
}
}
Я также пробовал все решения в этом post от ScoRpion и этого post от K-Alex
Итак, где ПРОБЛЕМА ???
Внутри репозитория вы должны иметь доступ к диспетчеру сущности, как этот '$ this -> _ em'. Поэтому вы можете просто использовать: '$ this -> _ em-> createQuery()' – TheFrozenOne