[英]Symfony2 custom repository class
我是symfony2的新手,我正在嘗試創建自定義存儲庫類,並且無法做到。
這是我在做的事情:
@ORM \\實體(repositoryClass = “Maak \\ DefaultBundle \\實體\\ MobilePhonesRepository”)
在MobilePhonesRepository中,我創建了名為findAllMobilePhones()
自定義函數
在控制器我調用函數使用:
$ 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();
}
}
感謝所有人的時間。 最后我發現了這個問題。
我決定調試整個項目,發現沒有在XMLDriver中設置repository-class
,而該XMLDriver將在元數據中設置customRepositoryName
。 這是因為我使用XML映射,對於這個實體,我使用Annotations提供repositoryClass
。
再次感謝:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.