php - Symfony 生产映射异常 FOSUserBundle

标签 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

我收到以下错误:

[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)上没有出现此错误

目前我不知道出了什么问题。我后来在项目中确实从注释切换到了 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

你能尝试看看是否有效吗? 虽然我不确定 - 但尝试一下。

关于php - Symfony 生产映射异常 FOSUserBundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40224823/

相关文章:

Symfony2 : Call Voter from another Voter

php - Symfony 类加载器 - 用法?没有实际使用的例子

mysql - 使用 Doctrine 统计关联实体时如何避免大量查询?

php - 教义一对一单向错误拯救 child

Symfony2 - 查询生成器多个 orderBy

php - 如何将PHP连接到MySQL数据库?

php - OOP PHP 和 'Get-Set'

javascript - opencart 2.0 中搜索按钮移至顶部栏

php - OpenID——获取用户信息?

php - Symfony2 在自定义文件夹中生成 Controller