T
T
Tarakkolya2014-06-17 22:35:25
Doctrine ORM
Tarakkolya, 2014-06-17 22:35:25

How to work with Doctrine 2 custom repositories?

There is a Place entity, I add a custom repository, as described here 8.8.7: odiszapc.ru/doctrine/working-with-objects/#881
and when calling the method of this repository, it gives an error that there is no such method. Maybe I wrote something wrong, or do I need to add an entry somewhere else? I use ZF2.
Entity\Place code:

namespace Application\Entity;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping as ORM;

/** 
 * Application\Entity\Place 
 * @ORM\Entity(repositoryClass="Application\Entity\PlaceRepository")
 * 
 */

/** @ORM\Entity */
class Place {
   /***тут поля Place***/
}



class PlaceRepository extends EntityRepository{
    public function getAll(){
        return $this->_em->createQuery('SELECT u FROM Application\Entity\Place u')->getResult();
    }
}

Code in controller:
$places=$em->getRepository('Application\Entity\Place')->getAll();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-06-17
@Tarakkolya

Well, it's not in the phpdoc before the class. Try like this:

/** 
 * Application\Entity\Place 
 * @ORM\Entity(repositoryClass="\Application\Entity\PlaceRepository")
 */
class Place {
   /***тут поля Place***/
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question