教义2,未定义的实体方法findOneBy * [英] Doctrine 2, undefined entity method findOneBy*

查看:107
本文介绍了教义2,未定义的实体方法findOneBy *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。以下是错误消息:



调用未定义的方法 MyProject\BlogBu​​ndle\Entity\Blog :: findOneById()



我已经设置了映射,实体类是使用控制台创建的,我已经更新了数据库中的模式。可能导致这个问题?



我使用symfony2。这是行:

  $ blogRepo = $ this-> get('myproject.blog.repository.blog'); 
$ blog = $ blogRepo-> findOneById($ id);

任何想法?

解决方案

findOneById不存在,尝试


$ blogRepo-> findOneBy(array('id'=> $ id));


其中'id'是您的实体中的现有字段。



您可以在这里查看教义的课程文档: EntityRepository



编辑:只要实体有一个字段Id,就像findOneById一样存在。 检查文档。 Thx to Ryall指出它


I have a strange issue. Here is the error message:

Call to undefined method MyProject\BlogBundle\Entity\Blog::findOneById()

I have setup the mapping, the entity class was created using the console and I have updated the schema in the database. What could be causing this issue?

I'm using symfony2. Here is the line:

$blogRepo = $this->get('myproject.blog.repository.blog');  
$blog = $blogRepo->findOneById($id);  

Any ideas?

解决方案

findOneById doesn't exist, try

$blogRepo->findOneBy(array('id' => $id));

where 'id' is an existing field in your Entity.

You can check the Doctrine's class documentation here: EntityRepository

Edit: looks like findOneById does exist as long as the entity has a field "Id". Check the docs. Thx to Ryall for pointing it out

这篇关于教义2,未定义的实体方法findOneBy *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆