FOSUserBundle生成:实体不起作用,字段的访问级别过高 [英] FOSUserBundle generate:entities does not work, Access level of fields too high

查看:107
本文介绍了FOSUserBundle生成:实体不起作用,字段的访问级别过高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我用StofDoctrineExtensionsBundle配置了DoctrineExtensions之后,我对FOSUserBundle遇到了问题。

I have a problem with FOSUserBundle after I configured DoctrineExtensions, with StofDoctrineExtensionsBundle.

首先,要安装DoctrineExtensions,必须从中删除 auto_mapping:true段app / config / config.yml文件。

First of all, to install DoctrineExtensions I had to remove "auto_mapping: true" segment from app/config/config.yml file.

我发现,如果auto_mapping未激活,则必须在默认的:mappings段中包含FOSUserBundle:〜。

I found that if auto_mapping is not active I have to include FOSUserBundle: ~ in default:mappings segment.

但是,当我尝试

php app/console doctrine:schema:update --force

php app/console doctrine:generate:entities FOS

我得到:

PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
Generating entities for namespace "FOS"
PHP Fatal error:  Access level to FOS\UserBundle\Entity\User::$username must be protected (as in class FOS\UserBundle\Model\User) or weaker in /var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php on line 17
PHP Stack trace:
PHP   1. {main}() /var/www/rBay/app/console:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/rBay/app/console:22
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:105
PHP   4. Symfony\Component\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:78
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:192
PHP   6. Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:238
PHP   7. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getNamespaceMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php:109
PHP   8. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getMetadataForNamespace() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:97
PHP   9. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:160
PHP  10. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:196
PHP  11. Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:111
PHP  12. Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:132
PHP  13. require_once() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:194
PHP  14. Symfony\Component\ClassLoader\DebugClassLoader->loadClass() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:0
PHP  15. require() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:82

Fatal error: Access level to FOS\UserBundle\Entity\User::$username must be protected (as in class FOS\UserBundle\Model\User) or weaker in /var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php on line 17

Call Stack:
0.0002     644752   1. {main}() /var/www/rBay/app/console:0
0.0132    3467080   2. Symfony\Component\Console\Application->run() /var/www/rBay/app/console:22
0.0155    3851816   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:105
2.3154   50066792   4. Symfony\Component\Console\Application->doRun() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:78
2.3187   50066792   5. Symfony\Component\Console\Command\Command->run() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:192
2.3192   50068328   6. Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:238
2.3208   50178008   7. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getNamespaceMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php:109
2.3208   50178008   8. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getMetadataForNamespace() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:97
2.3208   50178320   9. Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:160
2.3307   50203984  10. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() /var/www/rBay/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:196
2.3308   50204456  11. Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:111
2.3308   50205408  12. Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:132
2.3428   52000872  13. require_once('/var/www/rBay/src/MSoft/UserBundle/Entity/User.php') /var/www/rBay/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:194
2.3428   52001400  14. Symfony\Component\ClassLoader\DebugClassLoader->loadClass() /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:0
2.3431   52081336  15. require('/var/www/rBay/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Entity/User.php') /var/www/rBay/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/DebugClassLoader.php:82

我还将附加配置文件的相关区域,以防万一...

I'll attach related regions of my config file, as well, just in case...

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%
    entity_managers:
        default:
            connection: default
            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
                gedmo_loggable:
                    type: annotation
                    prefix: Gedmo\Loggable\Entity
                    dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
                    alias: GedmoLoggable # this one is optional and will default to the name set for the mapping
                    is_bundle: false
                gedmo_tree:
                    type: annotation
                    prefix: Gedmo\Tree\Entity
                    dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                    alias: GedmoTree # this one is optional and will default to the name set for the mapping
                    is_bundle: false
                MSoftAdminBundle: ~
                MSoftUserBundle: ~
                FOSUserBundle: ~

# Fosuser Configuration
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: MSoft\UserBundle\Entity\User

stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            tree: true
            sluggable: true

我在做什么错? / p>

What am I doing wrong?

推荐答案

已解决。当我运行时出现问题

Solved. Problem appeared when I ran

php app/console doctrine:generate:entities FOS

比学说实体生成器增加了原本不应该存在的属性,这带来了问题。
关键是类FOS\UserBundle\Entity\User应该具有空主体,并且生成器从FOS\UserBundle\Model\User中创建了所有字段,只是具有更高的保护级别( 私有而不是受保护)。

Than doctrine entity generator added properties that wasn't supposed to be there, and that made a problem. The point is that class FOS\UserBundle\Entity\User should have empty body, and generator created all the fields from FOS\UserBundle\Model\User in it, just with higher protection level ("private" instead of "protected").

这篇关于FOSUserBundle生成:实体不起作用,字段的访问级别过高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆