类存储库在symfony 2中不起作用

时间:2015-04-26 16:43:13

标签: symfony repository

这是我的代码:

file Entity / Article.php

namespace Kaker\FormularzBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="article")
 * @ORM\Entity(repositoryClass="Kaker\FormularzBundle\Entity\ArticleRepository")
 */
 class Article {...}

文件Entity / ArticleRepository:

namespace Kaker\FormularzBundle\Entity;

use Doctrine\ORM\EntityRepository;

class ArticleRepository extends EntityRepository
{
    public function getNickInfo($nick)
    {
    return $this->getEntityManager()
        ->createQuery(
            'SELECT a FROM KakerFormularzBundle:Article a WHERE a.nick = :nick '
        )
        ->setParameter('nick', $nick)
        ->getResult();
    }
}

文件UserController

$em = $this->getDoctrine()->getManager();
$article = $em->getRepository("KakerFormularzBundle:Article")
            ->getNickInfo($nick);

我有这个错误:

  

警告:缺少Doctrine \ ORM \ EntityRepository :: __ construct()的参数1,在第1496行的/var/www/apps/sf2-podstwy/app/cache/dev/appDevDebugProjectContainer.php中调用并定义

0 个答案:

没有答案