17

symfony2 プロジェクトに 2 つのバンドルがあります。1 つは Bundle で、もう 1 つは 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 内部サーバー エラー - 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

私の場合、プロバイダーの下のsecurity.ymlに名前空間名がありませんでした

私が持っていた:

entity: { class: AdministratorBundle:AdminUser }

そして、以下が必要です:

entity: { class: NamespaceAdministratorBundle:AdminUser }

于 2014-10-08T12:19:03.100 に答える
6

2 つ以上のエンティティ マネージャーを使用する場合 -- manager も指定する必要があります getManager('YourManager')

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

バンドルの論理名 (MunichInnovationGroupPatentBundle) を確認します。バンドルの論理名は、バンドルのメイン クラスの名前です。例: JobsBundle

エンティティのソースコードを提供します。

于 2012-06-17T09:11:03.120 に答える
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で 、バンドルが有効になっているかどうかを確認することを忘れないでください:

        new MunichInnovationGroup\PatentBundle\MunichInnovationGroupPatentBundle(),
于 2016-12-14T06:23:39.017 に答える
0

コアフォルダー名なしでバンドル名を使用しようとしたときに、これがありました。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

このエラーは、複数のエンティティ マネージャーを使用しており、コントローラー関数でエンティティ マネージャーを指定していない場合に発生します。

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

これは私のために働いた。

于 2014-03-21T18:35:20.407 に答える