我是 symfony 2 的新手。我试图在 symfony 2 中使用自定义存储库。在 detailsRepository.php 文件中编写函数后。在我写的 Controller 中
$em = $this->getDoctrine()->getEntityManager();
$products = $em->getRepository('BundlesampleBundle:details')
->findAllWhoseEmailContains($value);
但我收到的错误是
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)
我的 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();
}
}
提前致谢。
最佳答案
您是否为所有类添加了所有必要的注释,就像这里所说的:http://symfony.com/doc/current/doctrine/repository.html ?
您使用的是最新的 Symfony 2.0.5 吗?
关于doctrine-orm - 在 Symfony 2 中使用自定义存储库时显示错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8075258/