我是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();
}
}
Run Code Online (Sandbox Code Playgroud)