- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用 Symfony2 并且收到此错误消息:
未定义的方法“getDoctrine”。方法名称必须以 findBy 或 findOneBy 开头!
500 内部服务器错误 - BadMethodCallException
这是我的实体类:
<?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');
}
}
<?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();
}
}
最佳答案
在 Repository 类中,而不是:
$em = $this->getDoctrine()->getEntityManager();
$em = $this->getEntityManager();
关于symfony - 未定义的方法 'getDoctrine' 。方法名称必须以 findBy 或 findOneBy 开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32869616/
我正在尝试在 Controller 之外使用 getDoctrine()。 我创建了这个服务: 配置/服务.yml services: update_command: class: pro
我正在尝试创建小型应用程序以使用 symfony/doctrine 通过 id 从表中读取记录。 我的步骤: 创建 Controller (GS\OrderBunndle\Controller\Cus
我正在尝试实现自定义选民。 从 Controller 我这样称呼它: $prj = $this->getDoctrine()->getRepository('AppBundle:Project')->
在 Symfony 中,我发现了三种访问学说服务和实体管理器的方法,如下所示: $em = $this->getDoctrine()->getManager(); $em = $this->get('
这两种说法有什么区别吗: $this->getDoctrine()->getEntityManager()->getRepository(); $this->getDoctrine()->getRep
我需要创建一个州的下拉列表,这样一旦我从国家 drop_down 中选择国家,那么该国家的州 drop_down 就应该使用 Ajax 出现。我收到以下错误后的错误。 Attempted to cal
我看过一些关于这个主题的帖子,但没有找到我正在寻找的答案。当我从一个方法调用 $this->getDoctrine(); 时,说 public function returnObjectAction(
我目前正在使用 Symfony2 并且收到此错误消息: 未定义的方法“getDoctrine”。方法名称必须以 findBy 或 findOneBy 开头! 500 内部服务器错误 - BadMeth
我是一名优秀的程序员,十分优秀!