I’m trying to implement Repositories in my app to separate DQL from the rest of the Entity logic but I am getting a Class 'UserRepository' not found in /home/fiodorovich/public_html/tests/library/Doctrine/ORM/EntityManager.php on line 567 exception.
This is what my User class has:
/**
* Description of User
* @Table(name="users")
* @Entity(repositoryClass="UserRepository")
* @author fiodorovich
*/
And this is the repository I’ve created:
namespace Federico\Entity\Repository;
use Doctrine\ORM\EntityRepository;
class UserRepository extends EntityRepository
{
public function getAllUsers () {
$users = $this->em->createQuery('SELECT u FROM Federico\Entity\User u JOIN u.countries')->getResult();
return $users;
}
public function getUser ($id) {
$query = $this->em->createQuery('SELECT u, c FROM Federico\Entity\User u JOIN u.countries c WHERE c.user = ?1');
$query->setParameter(1, $id);
$userModel = $query->getSingleResult();
return $userModel;
}
}
And finally, this is the line I use to call it from the controller:
$this->em->getRepository('Federico\Entity\User')->getAllUsers();
Any help will be cool as I really want to use repositories
I think you should use
@Entity(repositoryClass="Repository\UserRepository")– relative to the Entitybecause I assume your repository classes are in
Federico\Entity\Repository