symfony + Mapping错误

时间:2013-03-04 08:13:35

标签: symfony symfony-2.1 symfony-2.2

我正在我的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 个答案:

答案 0 :(得分:7)

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

1)使用auto_mapping

doctrine:
    orm:
        auto_mapping: true

2)没有auto_mapping

doctrine:
    orm:     
        mappings:
            AcmeUserBundle: ~

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

答案 1 :(得分:3)

它也可以提供帮助:

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

...
new Acme\UserBundle\AcmeUserBundle(),
...

答案 2 :(得分:0)

将以下行添加到app/AppKernel.php文件的数据包阵列中:

new FOS\UserBundle\FOSUserBundle()

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

答案 3 :(得分:0)

我的解决方案:

更改../ Entity / User.php

命名空间Acme \ UserBundle \ Entity;使用命名空间Acme \ Bundle \ UserBundle \ Entity;

并在app / config.yml中更改

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

问候,Amic