类存储库在symfony 2中不起作用
这是我的密码: 文件Entity/Article.php 文件实体/存储库:类存储库在symfony 2中不起作用,symfony,repository,Symfony,Repository,这是我的密码: 文件Entity/Article.php 文件实体/存储库: namespace Kaker\FormularzBundle\Entity; use Doctrine\ORM\EntityRepository; class ArticleRepository extends EntityRepository { public function getNickInfo($nick) { return $this->getEntityManager(
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();
}
}
文件用户控制器
$em = $this->getDoctrine()->getManager();
$article = $em->getRepository("KakerFormularzBundle:Article")
->getNickInfo($nick);
我有一个错误:
警告:在第1496行的/var/www/apps/sf2 podstwy/app/cache/dev/appDevDebugProjectContainer.php中调用并定义的条令\ORM\EntityRepository::uu构造缺少参数1
可能重复的您是否确定您没有尝试在某个地方创建新的ArticleRepository?也许您已经将它定义为一个服务,并且正在尝试将它注入到某些东西中。通常,使用EntityManager::getRepository$entityClassName创建存储库。您的特定错误消息表明有东西正试图直接新建它$rows=$em->getRepositoryKakerFormularzBundle:Article->getAllArticle;,但是在UserController中,相同的代码不起作用
$em = $this->getDoctrine()->getManager();
$article = $em->getRepository("KakerFormularzBundle:Article")
->getNickInfo($nick);