我是symfony 2的新手。我正在尝试在symfony 2中使用自定义存储库。在detailsRepository.php文件中编写该函数之后。在我写的控制器中
$em = $this->getDoctrine()->getEntityManager();
$products = $em->getRepository('BundlesampleBundle:details')
->findAllWhoseEmailContains($value);
但我收到错误
警告:缺少Doctrine \ ORM \ EntityRepository :: __ construct()的参数1,在第162行的C:\ xampp \ htdocs \ symblog \ src \ Bundle \ sampleBundle \ Controller \ DefaultController.php中调用,并在C中定义: \ xampp \ htdocs \ symblog \ vendor \ doctrine \ lib \ Doctrine \ ORM \ EntityRepository.php第61行(500内部服务器错误)
我的detailsRepository.php如下
<?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();
}
}
提前致谢。
答案 0 :(得分:1)
您是否已将所有必要的注释添加到所有类中,如此处所述:http://symfony.com/doc/current/doctrine/repository.html? 您使用的是最新的Symfony 2.0.5吗?