Symfony生产映射异常FOSUserBundle

时间:2016-10-24 18:12:28

标签: php symfony doctrine-orm fosuserbundle

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

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

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

我收到以下错误:

  

[学说\ ORM \映射\ MappingException]    “FOS \ UserBundle \ Model \ User”类“AppBundle \ Entity \ User”子类不是有效实体或映射超类。

我的开发机器(Windows 10桌面和Macbook)上没有出现此错误

目前我不知道可能出现什么问题。我在项目的后期确实从注释切换到了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"]

2 个答案:

答案 0 :(得分:2)

我不是100%肯定,但我see a note here user是一个保留的SQL关键字,您可能需要像这样更改src/AppBundle/Resources/config/doctrine/User.orm.yml文件:

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

你能试试看看是否有效吗? 我不确定 - 但试试吧。

答案 1 :(得分:1)

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

我的修复:将src/AppBundle/

中的文件夹资源大写