Symfony 生产映射异常 FOSUserBundle

Symfony production Mapping Exception FOSUserBundle

我在 Whosebug 上搜索了我的问题,但没有找到问题的答案。

目前我正在我的 Debian 服务器上部署我的 symfony 项目 运行 PHP 5.6.26 following the documentation on the symfony website.

当我通过 运行 命令执行安装包的命令时 composer install --no-dev --optimize-autoloader

我收到以下错误:

[Doctrine\ORM\Mapping\MappingException] Class "AppBundle\Entity\User" sub class of "FOS\UserBundle\Model\User" is not a valid entity or mapped super class.

我的开发机器(Windows 10 台台式机和一台 Macbook)上没有这个错误

目前我不知道哪里出了问题。我在项目后期确实从annotation切换到了yml。

我的 User.php 文件:

<?php

namespace AppBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;

/**
 * User
 */
class User extends BaseUser
{

    public function __construct()
    {
        parent::__construct();
    }

    protected $id;

    /**
     * @var \AppBundle\Entity\Address
     */
    private $address;


    /**
     * Set address
     *
     * @param \AppBundle\Entity\Address $address
     *
     * @return User
     */
    public function setAddress(\AppBundle\Entity\Address $address = null)
    {
        $this->address = $address;

        return $this;
    }

    /**
     * Get address
     *
     * @return \AppBundle\Entity\Address
     */
    public function getAddress()
    {
        return $this->address;
    }
}

和我的 User.orm.yml 文件:

AppBundle\Entity\User:
    type: entity
    table: user
    repositoryClass: AppBundle\Repository\UserRepository
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
    lifecycleCallbacks: {  }

    oneToOne:
      address:
        targetEntity: AppBundle\Entity\Address
        cascade: ["persist", "remove"]

我不是 100% 确定,但我 see a note here user 是保留的 SQL 关键字,您可能需要更改 src/AppBundle/Resources/config/doctrine/User.orm.yml 文件,例如所以:

AppBundle\Entity\User:
    type: entity
    table: fos_user

你试试看行不行? 虽然我不确定 - 但试试吧。

看到Alvin Bunk的回答后,我看到文件夹Resources(在src/AppBundle)在他的回答中是大写的。 检查后,我的文件夹Resources没有大写。

我的修复:将 Resources 中的文件夹大写 src/AppBundle/