0

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

从另一个包的 FrontController 中,我得到了快速链接包,将容器对象注入到包类(上图)中,然后在包类中提取模板以返回 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() 方法的存储库类。

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

谢谢,

麦克风

4

1 回答 1

2

改变:

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

到:

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

我假设您有一个名为“快速链接”的实体

于 2012-04-07T13:17:30.533 回答