如何从symfony2中的bundle类访问存储库?

时间:2012-04-07 08:26:04

标签: symfony repository bundle

所以,我使用bundle类来完成我的大部分工作,因为我不需要控制器(src \ CSFs \ QuicklinksBundle \ CSFsQuicklinksBundle.php)。

从另一个bundle的FrontController,我得到quicklinks包,将容器对象注入bundle类(上面),然后在bundle类中提取templating以返回HTML,这很好。但是,我在存储库方面遇到了问题。

/**
 * Get the container object, so we can use all the symfony2 fun stuffs
 */
public function injectContainer($cont) 
{
    // Template
    $this->tpl = $cont->get('templating');

    // EM
    $this->em = $cont->get('doctrine')->getEntityManager();
}

/**
 *
 **/
public function doStuff()
{
    $products = $this->em->getRepository('QuicklinksBundle:Quicklinks')
                ->getUsersWithQuicklinks();
}

我得到的错误是:

Unknown Entity namespace alias 'QuicklinksBundle'.

我同时生成了实体文件和一个定义了getUsersWithQuicklinks()方法的存储库类。

如何让实体经理了解我的存储库?

谢谢,

麦克

1 个答案:

答案 0 :(得分:2)

变化:

$this->em->getRepository('QuicklinksBundle:Quicklinks')

要:

$this->em->getRepository('CSFsQuicklinksBundle:Quicklinks')

我假设你有一个名为'Quicklinks'的实体