3

User Entity :

namespace Core\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * User
 * @ORM\Entity(repositoryClass="Core\UserBundle\Entity\UserRepository")
 * @ORM\Table(name="user")
 */
class User
{
}

User Repository :

<?php 
# src/Core/UserBundle/Entity/UserRepository.php

namespace Core\UserBundle\Entity;
use Doctrine\ORM\EntityRepository;

class UserRepository extends EntityRepository
{

    public function example()
    {
        return "hello word";
    }
}

Controller :

$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('CoreUserBundle:User');
$repo->example();

Note : get_class($repo) => Doctrine\ORM\EntityRepository

The error:

Error Message : Undefined method 'example'. The method name must start with either findBy or findOneBy!
Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97
Murat SAÇ
  • 396
  • 1
  • 3
  • 13

1 Answers1

0

Try with this

$repo = $em->getRepository('UserBundle:User');

Zarpele
  • 513
  • 1
  • 6
  • 10