我是 symfony2 的新手,我正在尝试创建自定义存储库类,但无法做到。
这是我正在做的事情:
@ORM\Entity(repositoryClass="Maak\DefaultBundle\Entity\MobilePhonesRepository")
$em->getRepository('MaakDefaultBundle:MobilePhones')->findAllMobilePhones();
但我得到Undefined method findAllMobilePhones()
,我已清除缓存并尝试但同样的错误。怎么了?
我的存储库类:
<?php
namespace Maak\DefaultBundle\Entity;
use Doctrine\ORM\EntityRepository;
class MobilePhonesRepository extends EntityRepository
{
public function findAllMobilePhones()
{
return $this->getEntityManager()->createQuery('SELECT p FROM AcmeStoreBundle:Product p ORDER BY p.name ASC') ->getResult();
}
}
感谢大家抽出宝贵的时间。最后我发现了这个问题。
我决定调试整个项目并发现repository-class
未在将要设置的 XMLDriver 中设置customRepositoryName
在元数据中。这是因为我正在使用 XML 映射,并且我为这个实体提供了repositoryClass
使用注释。
再次感谢:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)