I have the class user repository
class userRepository extends EntityRepository
{
function getuserData($id)
{
$query = $this->createQuery('
SELECT c FROM AcmeBundle:User c
WHERE c.id = :id ORDER BY c.id ASC
')
->setParameter('id', $id);
return $query->getResult();
}
}
I am getting this error
Undefined method 'createQuery'. The method name must start with either findBy or findOneBy!
According to docs
$em = $this->getEntityManager();
$query = $em->createQuery('
SELECT p FROM AcmeStoreBundle:Product p
WHERE p.price > :price
ORDER BY p.price ASC
')
->setParameter('price', '19.99');
$products = $query->getResult();
I know this answer is quite late but your userRepository class needs to be defined in your User entity.
use Doctrine\ORM\Mapping as ORM
/**
* @ORM\Entity(repositoryClass="NameOfBundle\Repository\UserRepository")
class User
{
...
}
When we work at Repositories
$em = $this->getEntityManager(); //wont work in repository
$em->createQueryBuilder($sql);
you have to use
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->prepare($sql);
Read More
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With