0

我在使用可翻译扩展时遇到问题。

我的 composer.json 是这样的:

...
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.*",
"stof/doctrine-extensions-bundle": "@dev",
"gedmo/doctrine-extensions": "2.3.*@dev"
...

我的 config.yml 是这样的:

# Translatable Configuration
stof_doctrine_extensions:
    default_locale: br
    translation_fallback: true
    orm:
        default:
            tree: true
            translatable: true # not needed: listeners are not enabled by default

但是当我尝试拨打这个电话时:

$translatable = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');

我有这个错误:

在链配置的命名空间 Project\Portal\SampleBundle\Entity、Project\Portal\ExampleBundle\Entity、Project\Portal\CoreBundle\Entity 中找不到类“Gedmo\Translatable\Entity\Translation”

有谁知道发生了什么,我该如何解决?

谢谢!

4

2 回答 2

2

我有同样的错误,但我使用的是 Zend Framework 2。

缺少的部分是我的配置中可翻译实体的原则驱动程序:

<?php
return array(
    'doctrine' => array(
        'driver' => array(
            'base_entities' => array(
                'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Base/Entity')
            ),
            // here
            'translatable_entities' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    'Base\Entity' => 'base_entities',
                     // and here
                    'Gedmo\Translatable\Entity' => 'translatable_entities'
                )
            )
        )
    );

并且不要忘记在您的模块引导程序中附加 TranslatableListener。

<?php

namespace Base;

use Zend\Mvc\ModuleRouteListener;

use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature;

class Module implements
    Feature\BootstrapListenerInterface {

    public function onBootstrap(EventInterface $e) {

        $sm = $e->getApplication()->getServiceManager();
        $em = $sm->get('doctrine.entitymanager.orm_default');
        $doctrineEventManager = $em->getEventManager();

        $translatableListener = new \Gedmo\Translatable\TranslatableListener();         
        $translatableListener->setDefaultLocale('de');
        $doctrineEventManager->addEventSubscriber($translatableListener);
于 2013-07-24T16:12:50.650 回答
0

仅供参考,您还可以在模块配置中添加侦听器:

'doctrine' => array(
    ...
    'eventmanager' => array(
        'orm_default' => array(
            'subscribers' => array(
                'Gedmo\Sluggable\SluggableListener',
                'Gedmo\Timestampable\TimestampableListener',
                'Gedmo\SoftDeleteable\SoftDeleteableListener',
                'Gedmo\Loggable\LoggableListener',
                 ...
            ),
        ),
    ),
),
于 2014-10-21T23:46:43.690 回答