0

使用 StofDoctrineExtensionsBundle 配置 DoctrineExtensions 后,FOSUserBundle 出现问题。

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

我发现如果 auto_mapping 未激活,我必须在 default:mappings 段中包含 FOSUserBundle: ~ 。

但是,当我尝试

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

我也会附上我的配置文件的相关区域,以防万一......

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

我究竟做错了什么?

4

2 回答 2

2

Solved. Problem appeared when I ran

php app/console doctrine:generate:entities FOS

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").

于 2012-11-17T08:55:50.897 回答
1

User 类的所有属性都应该受到保护,而不是公开的。

于 2012-11-17T06:39:03.920 回答