1

我正在我的 symfony 中实现 FOSUser 模块,我已经创建并配置了所有文件作为教程。这里是我的 config.yml 映射文件。

 namespace Acme\UserBundle\Entity;

 use FOS\UserBundle\Entity\User as BaseUser;
 use Doctrine\ORM\Mapping as ORM;


 class User extends BaseUser
 {

protected $id;

public function __construct()
{
    parent::__construct();
    // your own logic
}
}

它显示以下错误..

 MappingException: The class 'Acme\UserBundle\Entity\User' 
was not found in the chain configured namespaces FOS\UserBundle\Entity

这是我的 config.yml 文件,我在其中提到了自动加载。仍然无法正常工作。

      imports:
- { resource: parameters.yml }
- { resource: security.yml }

  framework:
 #esi:             ~
 #translator:      { fallback: %locale% }
 secret:          %secret%
 router:
    resource: "%kernel.root_dir%/config/routing.yml"
    strict_requirements: %kernel.debug%
form:            ~
csrf_protection: ~
validation:      { enable_annotations: true }
templating:
    engines: ['twig']
    #assets_version: SomeVersionScheme
default_locale:  "%locale%"
trusted_proxies: ~
session:         ~
fragments:       ~

# Twig Configuration
twig:
debug:            %kernel.debug%
strict_variables: %kernel.debug%

 # Assetic Configuration
 assetic:
debug:          %kernel.debug%
use_controller: false
bundles:        [ ]
#java: /usr/bin/java
filters:
    cssrewrite: ~
    #closure:
    #    jar: %kernel.root_dir%/Resources/java/compiler.jar
    #yui_css:
    #    jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar

  # Doctrine Configuration
doctrine:
dbal:
    driver:   %database_driver%
    host:     %database_host%
    port:     %database_port%
    dbname:   %database_name%
    user:     %database_user%
    password: %database_password%
    charset:  UTF8
    # if using pdo_sqlite as your database driver, add the path in parameters.yml
    # e.g. database_path: %kernel.root_dir%/data/data.db3
    # path:     %database_path%

orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host:      %mailer_host%
username:  %mailer_user%
password:  %mailer_password%
spool:     { type: memory }
fos_user:
db_driver: orm 
firewall_name: main
user_class: Acme\UserBundle\Entity\User
4

4 回答 4

7

好的,这应该很容易。您需要auto_mapping在您的config.yml或手动指定“AcmeUserBundle:〜”那里启用:

1) 使用自动映射

doctrine:
    orm:
        auto_mapping: true

2) 没有自动映射

doctrine:
    orm:     
        mappings:
            AcmeUserBundle: ~

请注意,如果您有多个实体管理器,您将无法使用auto_mapping功能。希望这可以帮助!

于 2013-03-04T08:24:59.937 回答
3

它也可以帮助:

添加到您的 app/AppKernel.php 中:

...
new Acme\UserBundle\AcmeUserBundle(),
...
于 2013-05-26T13:09:47.213 回答
0

将以下行添加到app/AppKernel.php文件的捆绑数组中:

new FOS\UserBundle\FOSUserBundle()

这是为 Symfony 注册该命名空间。

于 2013-03-04T08:21:21.493 回答
0

对我的解决方案:

../Entity/User.php 中的更改

命名空间 Acme\UserBundle\Entity;带有命名空间 Acme\Bundle\UserBundle\Entity;

并在 app/config.yml 更改

user_class: Acme\UserBundle\Entity\User 与
user_class: Acme\Bundle\UserBundle\Entity\User

问候, 艾米克

于 2014-11-06T10:51:11.317 回答