Zf2导航中的Doctrine 2问题 - 奇怪的问题

时间:2014-02-20 15:49:43

标签: orm doctrine zend-framework2

我可以毫无问题地使用我所有控制器的教条

$em = $this->getServiceLocator()->get("doctrine.entitymanager.orm_default");
$newsItems = $em->getRepository('Website\Entity\News')->findAll();

foreach($newsItems as $item)
// do stuff here

序言:如果我使用Zend \ Db \ Adapter而不是Doctrine进行以下工作!

我在MyNavigationFactory实例化的MyNavigationObject中。 我有一个名为mainmenu的mysql表,有4条记录:home,news,company,contact

我想用Doctrine-Orm进行自己的导航。 我还有一个名为Mainmenu的实体。

我可以调用entityManager,结果由4条记录组成但是记录数为4的4倍。难以置信!

这是代码:

 protected function getPages(ServiceLocatorInterface $serviceLocator)
{
    if (null === $this->pages) {

        $em = $serviceLocator->get("doctrine.entitymanager.orm_default");
        $menuItems = $em->getRepository('Website\Entity\Mainmenu')->findAll();

        //return default key            
        $configuration['navigation'][$this->getName()] = array();       

        foreach ($menuItems as $menuItem)
        {                       
            $configuration['navigation'][$this->getName()][$menuItem->getName()] = array(
                    'label' => $menuItem->getLabel(),
                    'route' => $menuItem->getRoute(),
                    'controller' => $menuItem->getController(),
            );          
        }

        if (!isset($configuration['navigation'])) {
            throw new \Exception\InvalidArgumentException('Could not find navigation configuration key');
        }
        if (!isset($configuration['navigation'][$this->getName()])) {
            throw new Exception\InvalidArgumentException(sprintf(
                    'Failed to find a navigation container by the name "%s"',
                    $this->getName()
            ));
        }

        // refer to Mvc::Application object not to modulename
        $application = $serviceLocator->get('Application');
        $routeMatch  = $application->getMvcEvent()->getRouteMatch();
        $router      = $application->getMvcEvent()->getRouter();
        $pages       = $this->getPagesFromConfig($configuration['navigation'][$this->getName()]);

        $this->pages = $this->injectComponents($pages, $routeMatch, $router);
    }
    return $this->pages;

任何人都可以提供建议或重现问题吗?

再见

0 个答案:

没有答案