1

我正在将我的 Symfony 2.0 项目迁移到 2.1rc1 版本。安装并测试我的应用程序后stof/doctrine-extensions-bundlegedmo/doctrine-extensions我收到以下错误:

没有为“Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation”的实体“Company\TestBundle\Entity\PageTranslation”子类指定标识符/主键。每个实体都必须有一个标识符/主键。

我的config.yml样子是这样的:

# Doctrine Configuration
doctrine:
    dbal:        
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8                    

    orm:
        auto_generate_proxy_classes: %kernel.debug%        
        connection: default
        auto_mapping: true        
        mappings:
            gedmo_translatable:
                type: annotation
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                alias: GedmoTranslatable # this one is optional and will default to the name set for the mapping
                is_bundle: false
            gedmo_translator:
                type: annotation
                prefix: Gedmo\Translator\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
                alias: GedmoTranslator # this one is optional and will default to the name set for the mapping
                is_bundle: false

stof_doctrine_extensions:
    default_locale: en
    translation_fallback: true
    orm:
        default:               
            translatable: true
            sluggable: true                             

根据这个文件StofDoctrineExtensionsBundle应该没问题。我唯一不确定的是auto_mapping: true选项。

我在项目中更改的唯一代码是在我的CategoryTranslation class. 我已经更换:

use Stof\DoctrineExtensionsBundle\Entity\AbstractTranslation;

经过:

use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;

因为 Stof-bundle 不再有AbstractTranslation类了。

有人可以告诉我如何解决这个问题吗?

4

2 回答 2

0

如果您使用的是 StofDoctrineExtensions,则不需要gedmo/doctrine-extensions. 也不需要在 PageTranslation 中生成任何内容

于 2013-01-26T23:50:36.600 回答
0

我之前的 PageTranslation 实体:

class PageTranslation extends AbstractTranslation
{
    /**
     * All required columns are mapped through inherited superclass
     */
}

在命令行上生成实体后的我的 PageTranslation 实体:

class PageTranslation extends AbstractTranslation
{
    /**
     * All required columns are mapped through inherited superclass
     */

    /**
     * @var integer $id
     */
    private $id;

    /**
     * @var string $locale
     */
    private $locale;

    .....etc....

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set locale
     *
     * @param string $locale
     * @return PageTranslation
     */
    public function setLocale($locale)
    {
        $this->locale = $locale;

        return $this;
    }

    /**
     * Get locale
     *
     * @return string 
     */
    public function getLocale()
    {
        return $this->locale;
    }

    ..etc....
}
于 2012-08-19T17:58:05.593 回答