symfony2 中的未知实体命名空间别名 [英] Unknown Entity namespace alias in symfony2

查看:20
本文介绍了symfony2 中的未知实体命名空间别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我的 symfony2 项目中有两个包.一个是 Bundle,另一个是 PatentBundle.

Hey I have two bundles in my symfony2 project. one is Bundle and the other one is PatentBundle.

我的 app/config/route.yml 文件是

My app/config/route.yml file is

MunichInnovationGroupPatentBundle:
resource: "@MunichInnovationGroupPatentBundle/Controller/"
type:     annotation
prefix:   /
defaults:  { _controller: "MunichInnovationGroupPatentBundle:Default:index" }

MunichInnovationGroupBundle:
resource: "@MunichInnovationGroupBundle/Controller/"
type:     annotation
prefix:   /v1
defaults:  { _controller: "MunichInnovationGroupBundle:Patent:index" }

login_check:
pattern:   /login_check

logout:
pattern:   /logout

在我的控制器里面我有

<?php
namespace MunichInnovationGroup\PatentBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use JMS\SecurityExtraPatentBundle\Annotation\Secure;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Core\SecurityContext;

use MunichInnovationGroup\PatentBundle\Entity\Log;
use MunichInnovationGroup\PatentBundle\Entity\UserPatent;
use MunichInnovationGroup\PatentBundle\Entity\PmPortfolios;
use MunichInnovationGroup\PatentBundle\Entity\UmUsers;
use MunichInnovationGroup\PatentBundle\Entity\PmPatentgroups;
use MunichInnovationGroup\PatentBundle\Form\PortfolioType;
use MunichInnovationGroup\PatentBundle\Util\SecurityHelper;
use Exception;
/**
 * Portfolio controller.
 * @Route("/portfolio")
 */
class PortfolioController extends Controller {
/**
 * Index action.
 *
 * @Route("/", name="v2_pm_portfolio")
 * @Template("MunichInnovationGroupPatentBundle:Portfolio:index.html.twig")
 */
   public function indexAction(Request $request) {
    $portfolios = $this->getDoctrine()
    ->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')
    ->findBy(array('user' => '$user_id'));

           // rest of the method
  }

我的实体类

<?php

 namespace MunichInnovationGroup\PatentBundle\Entity;

 use Doctrine\ORM\Mapping as ORM;

  /**
  * MunichInnovationGroup\PatentBundle\Entity\PmPortfolios
  *
  * @ORM\Table(name="pm_portfolios")
  * @ORM\Entity
  */
  class PmPortfolios
  {
/**
 * @var string $id
 *
 * @ORM\Column(name="id", type="string", length=36, nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="UUID")
 */
private $id;

/**
 * @var string $portfolioName
 *
 * @ORM\Column(name="portfolio_name", type="string", length=255, nullable=false)
 */
private $portfolioName;

/**
 * @var text $description
 *
 * @ORM\Column(name="description", type="text", nullable=true)
 */
private $description;

/**
 * @var string $permalink
 *
 * @ORM\Column(name="permalink", type="string", length=255, nullable=false)
 */
private $permalink;

/**
 * @var string $sharingCode
 *
 * @ORM\Column(name="sharing_code", type="string", length=255, nullable=false)
 */
private $sharingCode;

/**
 * @var boolean $shared
 *
 * @ORM\Column(name="shared", type="boolean", nullable=false)
 */
private $shared;

/**
 * @var integer $sharedPortfolioCalls
 *
 * @ORM\Column(name="shared_portfolio_calls", type="integer", nullable=true)
 */
private $sharedPortfolioCalls;

/**
 * @var boolean $isDefault
 *
 * @ORM\Column(name="is_default", type="boolean", nullable=false)
 */
private $isDefault;

/**
 * @var UmUsers
 *
 * @ORM\ManyToOne(targetEntity="UmUsers")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 * })
 */
private $user;



/**
 * Get id
 *
 * @return string 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set portfolioName
 *
 * @param string $portfolioName
 */
public function setPortfolioName($portfolioName)
{
    $this->portfolioName = $portfolioName;
}

/**
 * Get portfolioName
 *
 * @return string 
 */
public function getPortfolioName()
{
    return $this->portfolioName;
}

/**
 * Set description
 *
 * @param text $description
 */
public function setDescription($description)
{
    $this->description = $description;
}

/**
 * Get description
 *
 * @return text 
 */
public function getDescription()
{
    return $this->description;
}

/**
 * Set permalink
 *
 * @param string $permalink
 */
public function setPermalink($permalink)
{
    $this->permalink = $permalink;
}

/**
 * Get permalink
 *
 * @return string 
 */
public function getPermalink()
{
    return $this->permalink;
}

/**
 * Set sharingCode
 *
 * @param string $sharingCode
 */
public function setSharingCode($sharingCode)
{
    $this->sharingCode = $sharingCode;
}

/**
 * Get sharingCode
 *
 * @return string 
 */
public function getSharingCode()
{
    return $this->sharingCode;
}

/**
 * Set shared
 *
 * @param boolean $shared
 */
public function setShared($shared)
{
    $this->shared = $shared;
}

/**
 * Get shared
 *
 * @return boolean 
 */
public function getShared()
{
    return $this->shared;
}

/**
 * Set sharedPortfolioCalls
 *
 * @param integer $sharedPortfolioCalls
 */
public function setSharedPortfolioCalls($sharedPortfolioCalls)
{
    $this->sharedPortfolioCalls = $sharedPortfolioCalls;
}

/**
 * Get sharedPortfolioCalls
 *
 * @return integer 
 */
public function getSharedPortfolioCalls()
{
    return $this->sharedPortfolioCalls;
}

/**
 * Set isDefault
 *
 * @param boolean $isDefault
 */
public function setIsDefault($isDefault)
{
    $this->isDefault = $isDefault;
}

/**
 * Get isDefault
 *
 * @return boolean 
 */
public function getIsDefault()
{
    return $this->isDefault;
}

/**
 * Set user
 *
 * @param MunichInnovationGroup\PatentBundle\Entity\UmUsers $user
 */
public function setUser(\MunichInnovationGroup\PatentBundle\Entity\UmUsers $user)
{
    $this->user = $user;
}

/**
 * Get user
 *
 * @return MunichInnovationGroup\PatentBundle\Entity\UmUsers 
 */
public function getUser()
{
    return $this->user;
}

}

我的bundle主类:MunichInnovationGroupPatentBundle.php

My bundle main class: MunichInnovationGroupPatentBundle.php

 <?php

  namespace MunichInnovationGroup\PatentBundle;

  use Symfony\Component\HttpKernel\Bundle\Bundle;

  class MunichInnovationGroupPatentBundle extends Bundle
 {
 }

当我尝试加载 localhost/web/app_dev.php/portfolio 时

when i try to load localhost/web/app_dev.php/portfolio

它说

   Unknown Entity namespace alias 'MunichInnovationGroupPatentBundle'.

我无法弄清楚这个错误如果有人有任何想法,请帮助我,我在谷歌上搜索了很多:(

I am unable to figure out this error please help me if anyone has any idea I googled it a lot :(

提前致谢500 内部服务器错误 - ORMException

Thanks in advance 500 Internal Server Error - ORMException

推荐答案

请检查您的 config.yml.

Please, check your config.yml.

entity_managersmappings 部分中进行了审查.
你应该有类似 MunichInnovationGroupPatentBundle: ~

Reviewed in section mappings of entity_managers.
You should have something like MunichInnovationGroupPatentBundle: ~

即:

doctrine:
    orm:
        entity_managers:
            defaults:
                mappings:
                    MunichInnovationGroupPatentBundle: ~

这篇关于symfony2 中的未知实体命名空间别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆