Error showing when using Custom repository in Symf

2019-04-29 11:25发布

I am new to symfony 2. I am trying to use custom repository in symfony 2. After writing the function in the detailsRepository.php file. in the controller I wrote

$em = $this->getDoctrine()->getEntityManager();
 $products = $em->getRepository('BundlesampleBundle:details')
            ->findAllWhoseEmailContains($value);

but i am getting the error as

Warning: Missing argument 1 for Doctrine\ORM\EntityRepository::__construct(), called in C:\xampp\htdocs\symblog\src\Bundle\sampleBundle\Controller\DefaultController.php on line 162 and defined in C:\xampp\htdocs\symblog\vendor\doctrine\lib\Doctrine\ORM\EntityRepository.php line 61 (500 Internal Server Error)

My detailsRepository.php is as follows

<?php

namespace Bundle\sampleBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * detailsRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */

class detailsRepository extends EntityRepository
{
    public function findAllWhoseEmailContains($value)
    {
        return $this->getEntityManager()
            ->createQuery('Select e.email from BundlesampleBundle:details e Where  e.email = :email')
            ->setParameter('email',$value)
            ->getResult();


    }   

}

Thanks in advance.

1条回答
女痞
2楼-- · 2019-04-29 11:45

Have you put all necessary annotations to all classes, like it's said here: http://symfony.com/doc/current/doctrine/repository.html ? Are you using latest Symfony 2.0.5?

查看更多
登录 后发表回答