教义2,未定义的实体方法findOneBy * [英] Doctrine 2, undefined entity method findOneBy*
问题描述
调用未定义的方法 MyProject\BlogBundle\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屋!