17

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

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

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;
}

}

我的捆绑主类:MunichInnovationGroupPatentBundle.php

 <?php

  namespace MunichInnovationGroup\PatentBundle;

  use Symfony\Component\HttpKernel\Bundle\Bundle;

  class MunichInnovationGroupPatentBundle extends Bundle
 {
 }

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

它说

   Unknown Entity namespace alias 'MunichInnovationGroupPatentBundle'.

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

提前致谢 500 Internal Server Error - ORMException

4

11 回答 11

32

请检查您的 config.yml。

mappings在 部分进行了审查entity_managers
你应该有类似的东西MunichInnovationGroupPatentBundle: ~

那是:

doctrine:
    orm:
        entity_managers:
            defaults:
                mappings:
                    MunichInnovationGroupPatentBundle: ~
于 2012-09-27T07:31:07.827 回答
8

在我的情况下,我在 provider 下的 security.yml 中缺少命名空间名称

我有:

entity: { class: AdministratorBundle:AdminUser }

并且需要:

entity: { class: NamespaceAdministratorBundle:AdminUser }

于 2014-10-08T12:19:03.100 回答
6

如果您使用 2 个或更多实体管理器 - 您还需要指定管理器 getManager('YourManager')

$repository = 
    $this->getDoctrine()
    ->getManager('YourManager')
    ->getRepository('YourBundle:YourEntity');
于 2015-04-21T14:20:25.763 回答
2

检查您的捆绑逻辑名称 (MunichInnovationGroupPatentBundle)。Bundle 逻辑名称是你的 bundle 的主类的名称,例如 JobsBundle

并提供您的实体源代码。

于 2012-06-17T09:11:03.120 回答
1

Documentation here states you can use the string 'MunichInnovationGroupPatentBundle:PmPortfolios' as shortcut to 'MunichInnovationGroupPatentBundle\Entity\PmPortfolios' as long as your entity lives under the Entity namespace of your bundle.

Your bundle is MunichInnovationGroupBundle so instead of

->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')

use

->getRepository('MunichInnovationGroupPatentBundle\Entity\PmPortfolios')
于 2015-02-09T04:57:32.823 回答
1

请检查您的 config.yml + AppKernel.php

config.yml必须是

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true

或将auto_mapping替换为

    mappings:
        StoreShopBundle: ~

更多信息,请查看:https ://stackoverflow.com/a/37652091/5809937

AppKernel.php 中不要忘记检查 bundle 是否被激活:

        new MunichInnovationGroup\PatentBundle\MunichInnovationGroupPatentBundle(),
于 2016-12-14T06:23:39.017 回答
1

尝试通过添加一些字段在 config.yml 文件中更加明确:

orm:
    ...

    mappings:
        MunichInnovationGroupPatentBundle:
                type: annotation
                dir: "MunichInnovationGroupPatentBundle/Controller"
                is_bundle: true
                prefix: MunichInnovationGroup\PatentBundle
                alias: MunichInnovationGroupPatentBundle
        [more mappings..]
于 2015-09-19T11:25:51.833 回答
0

在 Symfony 2.3.7 版中,我使用了 NameofCompanySomethingBundle:EntityRequired 例如 AcmeBlogBu​​ndle:User 并且它可以工作。

auto-mapping: true (默认)在 orm: 下使用,在 config.yml 中。

于 2013-11-21T20:39:51.277 回答
0

如果您使用多个实体管理器并且未在控制器函数中指定实体管理器,则会发生此错误。

$em = $this->get('doctrine.orm.//your_entity_manager_name_here//_entity_manager');
$dql   = "SELECT ...";
$query = $em->createQuery($dql);

这对我有用。

于 2014-03-21T18:35:20.407 回答
0

当我尝试使用没有核心文件夹名称的 bandle 名称时,我遇到了这个问题。它在 config/security.yml

在我的情况下,文件夹结构是下一个 src/Dp/UserBundle/....

我改变了这个`提供者:

    main:
        entity: { class: UserBundle:User, property: username }`

对此`提供者:

    main:
        entity: { class: DpUserBundle:User, property: username }`

所以复制未知实体名称的名称并搜索项目中的每个条目,检查 - 它们必须带有文件夹前缀(在我的情况下为 Dp)

于 2013-08-08T10:20:24.947 回答
0

打开你的 app\config.yml,必须是

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true
replace to
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
              MunichInnovationGroupPatentBundle: ~
于 2018-06-19T13:56:44.533 回答