2012-06-16 4 views
12

Hey, ich habe zwei Pakete in meinem symfony2-Projekt. Eins ist Bundle und das andere ist PatentBundle.Unbekannter Entity-Namespace-Alias ​​in symfony2

Meine app/config/route.yml Datei ist

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 

in meinem Controller i

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

bearbeiten haben:

Meine Entity Klasse

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

}

Mein Bündel Hauptklasse: MunichInnovationGroupPatentBundle.php

<?php 

    namespace MunichInnovationGroup\PatentBundle; 

    use Symfony\Component\HttpKernel\Bundle\Bundle; 

    class MunichInnovationGroupPatentBundle extends Bundle 
{ 
} 

wenn ich versuche, localhost/web/app_dev.php/Portfolio

Es sagt

Unknown Entity namespace alias 'MunichInnovationGroupPatentBundle'. 

Ich bin zu laden nicht in der Lage, diesen Fehler herauszufinden, bitte helfen Sie mir, wenn jemand eine Idee hat, habe ich es viel googled :(

Vielen Dank im Voraus 500 Internal Server Error - ORMException

+0

Versuchen Sie, Ihre PmPortfolios Einheit zu überprüfen, wenn der Namespace richtig. –

+0

Eine andere mögliche Lösung: http://stackoverflow.com/questions/12145101/how-to-address-the-bundle-in-php-app-console-generatedoctrinecrud – CodeSlave

Antwort

2

prüfen bündeln Sie logischen Namen (MunichInnovationGroupPatentBundle). Der logische Name des Pakets ist der Name der Hauptklasse Ihres Bündels, z. JobsBundle

und geben Sie Ihren Entity-Quellcode.

+0

Ich fügte meine Entity Klassencode –

+0

haben Sie Symfony Protokolle überprüfen? – drupality

+0

nein, ich habe sie nicht überprüft –

26

Bitte überprüfen Sie Ihre config.yml.

Bewertet in Abschnitt mappings von entity_managers.
Sie sollten so etwas wie MunichInnovationGroupPatentBundle: ~

haben Das heißt:

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

Sollte es nicht genug mit ** auto_mapping: wahr **? – Jens

+2

Ich hatte gerade dieses Problem, indem ich in der Konfiguration meiner SF 2.3-App den Standard auto_mapping = true entfernte, um das stof/documentextensionsbundle-Mapping hinzuzufügen, nachdem SF2 eine Ausnahme ausgelöst hatte, dass auto_mapping kein gültiges Kind war. Das erneute Hinzufügen von auto_mapping als ein Geschwister des Knotens "mappings" (Kind von "defaults" anstelle von einem direkten Kind von "orm") oben behebt die Probleme. – nealio82

+0

Diese Antwort ist mein Problem gelöst. SF, siehe Namespaces über diesen Controller und starten Sie Build-Entities ordnungsgemäß. vollständige Beschreibung in dieser Antwort: http://stackoverflow.com/a/37652091/5809937 –

0

ich diese Bandle Name ohne Kern Ordnernamen zu verwenden, wenn versucht hatte. Es war in config/security.yml

Ordnerstruktur in meinem Fall ist die nächste src/DP/UserBundle/....

ich diese `Anbieter geändert:

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

dazu `Anbieter:

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

So Namen unbekannter Entity Namen kopieren und die einzelnen Einträge in Projekt suchen, überprüfen - sie mit Ordner Präfix sein müssen (Dp in mein Fall)

0

Wie in Symfony Version 2.3.7, ich NameofCompanySomethingBundle verwendet: EntityRequired z. AcmeBlogBundle: Benutzer und es funktioniert.

auto-mapping: true (Standard) wurde unter orm: in config.yml verwendet.

0

Dieser Fehler tritt auf, wenn Sie mehrere Entitätsmanager verwenden und Sie den Entitätsmanager in Ihrer Controllerfunktion nicht angeben.

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

das funktionierte für mich.

8

In meinem Fall war ich in dem security.yml unter Provider Namespace-Namen fehle

Ich hatte:

entity: { class: AdministratorBundle:AdminUser }

und haben muß:

entity: { class: NamespaceAdministratorBundle:AdminUser }

+0

Ich habe vergessen, dass die Root-Klasse des Bundles den Namespace am Anfang des Namens enthält. Vielen Dank! Beispiel für andere: Die Stammklasse für 'Company \ MyBundle' ist' CompanyMyBundle', nicht 'MyBundle'. – jxmallett

0

Dokumentation here können Sie die Zeichenfolge verwenden als Verknüpfung zu 'MunichInnovationGroupPatentBundle\Entity\PmPortfolios' solange Ihre Entität unter dem Entitätsnamespace Ihres Bündels lebt.

Ihr Paket ist MunichInnovationGroupBundle so statt

->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios') 

Verwendung

->getRepository('MunichInnovationGroupPatentBundle\Entity\PmPortfolios') 
5

Wenn Sie 2 oder mehr Entity-Manager verwenden - Sie müssen Manager angeben, auch getManager ('YourManager ')

$repository = 
    $this->getDoctrine() 
    ->getManager('YourManager') 
    ->getRepository('YourBundle:YourEntity'); 
+0

Diese Antwort sollte oben verschoben werden. Da ich fast die Hoffnung verloren habe und dann habe ich diese Lösung ausprobiert und es hat funktioniert. –

1

Probieren Sie explizit in Ihrer config.yml Datei zu sein, indem sie einige Feldern:

orm: 
    ... 

    mappings: 
     MunichInnovationGroupPatentBundle: 
       type: annotation 
       dir: "MunichInnovationGroupPatentBundle/Controller" 
       is_bundle: true 
       prefix: MunichInnovationGroup\PatentBundle 
       alias: MunichInnovationGroupPatentBundle 
     [more mappings..] 
+0

Ich wollte gerade eine Antwort wie diese hinzufügen, es funktionierte für mich mit dieser Herangehensweise, aber nicht, bis ich 'alias:' zu etwas anderem als 'MunichInnovationGroupPatentBundle' änderte:' alias: MunichInnovation' – juanmf

1

Bitte überprüfen Sie Ihre config.yml + AppKernel.php

config.yml muss

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

oder ersetzen auto_mapping mit

mappings: 
     StoreShopBundle: ~ 

für mehr, überprüfen Sie dies: https://stackoverflow.com/a/37652091/5809937

in AppKernel.php vergessen Sie nicht, zu überprüfen, ob Bündel aktiviert wird:

 new MunichInnovationGroup\PatentBundle\MunichInnovationGroupPatentBundle(),