I am new to symfony2 and I am trying to create custom repository class and couldn' do it.
Here is what I am doing:
- I added annotation to entity class ( MobilePhones )
@ORM\Entity(repositoryClass="Maak\DefaultBundle\Entity\MobilePhonesRepository")
In MobilePhonesRepository I created my custom function named
findAllMobilePhones()
In controller I called function using:
$em->getRepository('MaakDefaultBundle:MobilePhones')->findAllMobilePhones();
but I get Undefined method findAllMobilePhones()
, I have cleared cache and tried but same error. What is wrong?
My repository class:
<?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();
}
}
echo get_class($em->getRepository('MaakDefaultBundle:MobilePhones'))
return? Can you also provide the classfile for MobilePhonesRepository? – Seandoctrine2
to get max exposure. Also can you put your Repository code in the question so it's easily readable. – Bram GerritsencustomRepositoryName
is set in your metadata there will be an exception if it cannot be instanciated correctly. If it is still not working put avar_dump($metadata)
in the EntityManager on line 750 and show us the output. – Bram Gerritsen