Doctrine 2.4.x Gedmo扩展设置

时间:2015-01-28 18:12:38

标签: php doctrine-orm

我尝试让Translations为节点实体工作 到目前为止,我所做的只是将@Gedmo \ Translatable注释包含在$ headline属性中 不使用单独的TranslationEntity。

我安装了这些版本

behat/transliterator      v1.0.1             String transliterator
doctrine/annotations      v1.2.3             Docblock Annotations Parser
doctrine/cache            v1.4.0             Caching library offering an ob...
doctrine/collections      v1.2               Collections Abstraction library
doctrine/common           v2.4.2             Common Library for Doctrine pr...
doctrine/dbal             v2.5.1             Database Abstraction Layer
doctrine/inflector        v1.0.1             Common String Manipulations wi...
doctrine/lexer            v1.0.1             Base library for a lexer that ...
doctrine/orm              v2.4.7             Object-Relational-Mapper for PHP
gedmo/doctrine-extensions dev-master 4e9bbd5 Doctrine2 behavioral extensions
symfony/console           v2.6.3             Symfony Console Component 

遵循此setup from github

$cache = new ArrayCache;
    // standard annotation reader
    $annotationReader = new \Doctrine\Common\Annotations\AnnotationReader;
    $cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($annotationReader,$cache);
    // create a driver chain for metadata reading
    $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
    // load superclass metadata mapping only, into driver chain
    // also registers Gedmo annotations.NOTE: you can personalize it
    \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM(
    $driverChain, // our metadata driver chain, to hook into
    $cachedAnnotationReader // our cached annotation reader
    );

    // now we want to register our application entities,
    // for that we need another metadata driver used for Entity namespace
    $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(
    $cachedAnnotationReader, // our cached annotation reader
    array(ROOT_PATH.'/Achilles/Models/') // paths to look in
    );
    // NOTE: driver for application Entity can be different, Yaml, Xml or whatever
    // register annotation driver for our application Entity namespace
    $driverChain->addDriver($annotationDriver, 'Entities');

    // general ORM configuration
    $config = new \Doctrine\ORM\Configuration;
    $config->setProxyDir(ROOT_PATH.'/Achilles/Models/Proxies');
    $config->setProxyNamespace('Proxy');
    $config->setAutoGenerateProxyClasses(false); // this can be based on production config.
    // register metadata driver
    $config->setMetadataDriverImpl($driverChain);
    // use our already initialized cache driver
    $config->setMetadataCacheImpl($cache);
    $config->setQueryCacheImpl($cache);

    // create event manager and hook preferred extension listeners
    $evm = new \Doctrine\Common\EventManager();
    // gedmo extension listeners, remove which are not used

    // translatable
    $translatableListener = new \Gedmo\Translatable\TranslatableListener;
    // current translation locale should be set from session or hook later into the listener
    // most important, before entity manager is flushed
    $translatableListener->setTranslatableLocale('en');
    $translatableListener->setDefaultLocale('en');
    $translatableListener->setAnnotationReader($cachedAnnotationReader);
    $evm->addEventSubscriber($translatableListener);

    $connection = array(
    'driver' => 'pdo_mysql',
    'host' => '127.0.0.1',
    'dbname' => 'test',
    'user' => 'test',
    'password' => ''
    );
    // Finally, create entity manager
    $this->em = EntityManager::create($connection, $config, $evm);
    return $this->em;   

并继续收到此错误:

Exception: "exception 'Doctrine\Common\Annotations\AnnotationException' with message'[Semantical Error] The annotation "@Gedmo\Mapping\Annotation\Translatable" in property Entities\Nodes::$headline does not exist, or could not be auto-loaded.'  

我把它全部工作没有gedmo扩展但是对于翻译我想测试Gedmo并且卡在这里似乎没有任何工作了。
我没有使用Symfony或Zend。它是在我自己的自定义应用程序中实现的。

此设置有什么问题?

更新:自动加载配置如此

if(file_exists(ROOT_PATH . '/vendor/gedmo/doctrine-extensions/lib')){
        $extensionLoader = new ClassLoader('Gedmo', ROOT_PATH .'/vendor/gedmo/doctrine-extensions/lib');
        $extensionLoader->register();
    }

更新2:

<?php
namespace Entities;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Entity
 * @ORM\Table(name="nodes", options={"collate"="utf8_general_ci"})
 */
class Nodes {

    /** 
     * @ORM\Id 
     * @ORM\Column(type="integer") 
     * @ORM\GeneratedValue(strategy="AUTO") 
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Pages", inversedBy="_nodes")
     * @ORM\JoinColumn(name="pages_id", referencedColumnName="id")
     */
    private $_pages;

    /**
     * @Gedmo\Translatable
     * @ORM\Column(type="string", nullable=false)
     */
    private $headline;

0 个答案:

没有答案