在Symfony 2中使用自定义存储库时出现错误? [英] Error showing when using Custom repository in Symfony 2?

查看:90
本文介绍了在Symfony 2中使用自定义存储库时出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是symfony的新用户2.我正在使用symfony中的自定义存储库2.在detailsRepository.php文件中编写该函数。在控制器中,我写了

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);

但我收到错误为


警告:缺少参数1 for Doctrine\ORM\EntityRepository :: __ construct(),在C:\xampp\htdocs\symblog\src\Bundle\sampleBundle\\中调用第162行上的\\Controller\DefaultController.php并在C:\xampp\htdocs\symblog\vendor\doctrine\lib\Doctrine\ORM\EntityRepository.php行61(500内部服务器错误)

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如下

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();


    }   

}

提前感谢

推荐答案

您是否将所有必需的注释放在所有类中,就像这里所说的: http://symfony.com/doc/current/book/doctrine.html#custom-存储库类
您是否使用最新的Symfony 2.0.5?

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

这篇关于在Symfony 2中使用自定义存储库时出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆