2016-07-29 13 views
1

Es scheint, dass der Pfad zu Anmerkungen oder Namespaces falsch ist, aber ich kann nicht herausfinden warum. php bin/console doctrine:mongodb:mapping:info AusgängeSymfony2 Die Annotation "@Gedmo Mapping Annotation Timestampable" existiert nicht oder konnte nicht automatisch geladen werden

[FAIL] AppBundle\Document\Test\Test 
[Semantical Error] The annotation "@Gedmo\Mapping\Annotation\Timestampable" in property AppBundle\Document\Test\Test::$createdAt does not exist, or could not be auto-loaded. 

Entity-Datei:

<?php 

namespace AppBundle\Document\Test; 

use AppBundle\Document\Question\Question; 
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; 
use Gedmo\Mapping\Annotation as Gedmo; 

/** 
* @MongoDB\Document(repositoryClass="AppBundle\Document\Test\TestRepository") 
* @MongoDB\HasLifecycleCallbacks() 
*/ 
class Test 
{ 
    /** 
    * @MongoDB\Id(strategy="auto") 
    */ 
    protected $id; 


    /** 
    * @MongoDB\Field(type="string") 
    */ 
    protected $lastName; 


    /** 
    * @Gedmo\Timestampable(on="create") 
    * @MongoDB\Timestamp() 
    */ 
    protected $createdAt; 

Stackoverflow mir schon warnen, dass es meist Code ist in meinem Beitrag, aber ich glaube, ich habe composer.json Abschnitt zeigen:

"require": { 
    "alcaeus/mongo-php-adapter": "^1.0", 
    "symfony/symfony": "3.*", 
    "doctrine/orm": "^2.5", 
    "doctrine/doctrine-bundle": "^1.6", 
    "doctrine/common": "~2.4",   
    "doctrine/doctrine-cache-bundle": "^1.2", 
    "doctrine/mongodb-odm": "^1.0", 
    "doctrine/mongodb-odm-bundle": "3.*", 
    "gedmo/doctrine-extensions": "^2.4", 
    "symfony/monolog-bundle": "^2.8", 
    "sensio/distribution-bundle": "^5.0", 
    "sensio/framework-extra-bundle": "^3.0.2", 
    "incenteev/composer-parameter-handler": "^2.0", 
    "friendsofsymfony/user-bundle": "dev-master", 
    "stof/doctrine-extensions-bundle": "^1.2", 
}, 

Und ja, ich habe AnnotationDriver::registerAnnotationClasses(); in autoload.php. Ich habe bei vendor/composer/autoload_namespaces.php sah und es gibt Dinge, scheint ok zu:

<?php 

// autoload_namespaces.php @generated by Composer 

$vendorDir = dirname(dirname(__FILE__)); 
$baseDir = dirname($vendorDir); 

return array(
[...] 
    'Gedmo\\' => array($vendorDir . '/gedmo/doctrine-extensions/lib'), 
    'Doctrine\\ORM\\' => array($vendorDir . '/doctrine/orm/lib'), 
    'Doctrine\\ODM\\MongoDB' => array($vendorDir . '/doctrine/mongodb-odm/lib'), 
    'Doctrine\\MongoDB' => array($vendorDir . '/doctrine/mongodb/lib'), 
    'Doctrine\\DBAL\\' => array($vendorDir . '/doctrine/dbal/lib'), 
    'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'), 
    'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'), 
    'Doctrine\\Common\\Collections\\' => array($vendorDir . '/doctrine/collections/lib'), 
    'Doctrine\\Common\\Annotations\\' => array($vendorDir . '/doctrine/annotations/lib'), 
    'Behat\\Transliterator' => array($vendorDir . '/behat/transliterator/src'), 
); 
+0

Haben Sie es in Ihrer config.yml aktivieren? – Ziumin

+0

Ich denke schon. 'doctrine_mongodb: Verbindungen: default: Server: "mongodb: //% mongodb_host%:% mongodb_port%" Optionen: {} document_managers: default: auto_mapping: true' – dMedia

+0

Ich fragte nach' stof_doctrine_extensions' Abschnitt (lesen NDM Antwort bitte) – Ziumin

Antwort

0

Lösungen finden, die funktioniert. Haben Sie manuell die Anmerkungsdatei hinzufügen, in autoload.php in der Registrierung:

AnnotationRegistry::registerFile(__DIR__ . '/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Mapping/Annotation/Timestampable.php'); 
+0

Der interessante Teil ist, dass über Änderung erforderlich ist nur auf den ersten Lauf nach Cache-Bereinigung mit' pHP-bin/Konsole Cache: clear'. Dann kann es entfernt werden und alles funktioniert gut. – dMedia

+0

Und beim ersten Lauf muss ich auch 'AnnotationRegistry :: registerFile (__ DIR__. '/../ vendor/sensio/framework-extra-bundle/Konfiguration/Route.php');' hinzufügen. Sonst funktioniert das Routing nicht. – dMedia

2

Per documentation: Sie übersetzbar in Sie app/config.yml zu aktiv benötigen:

stof_doctrine_extensions: 
    mongodb: 
     default: 
      translatable: true 

und auch die Übersetzung Entitätszuordnungen zu Lehre hinzufügen :

doctrine: 
    orm: 
     mappings: 
      gedmo_translatable: 
       type: annotation 
       prefix: Gedmo\Translatable\Document 
       dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Document" 
       alias: GedmoTranslatable # (optional) it will default to the name set for the mapping 
       is_bundle: false 
      gedmo_translator: 
       type: annotation 
       prefix: Gedmo\Translator\Document 
       dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Document" 
       alias: GedmoTranslator # (optional) it will default to the name set for the mapping 
       is_bundle: false 
+0

Autor verwendet ODM, nicht ORM. Aber Optionen sollten ähnlich sein – Ziumin

+0

Sie sind richtig, ich habe geändert, um MongoDB zu reflektieren – NDM

+0

Vielen Dank für die Antwort, aber keine Notwendigkeit für Änderungen in 'app/config.yml'. Jetzt funktioniert es auch ohne "AnnotationRegistry :: registerFile" in autoload.php. Vielleicht war es ein Cache/Log-Problem. – dMedia

Verwandte Themen