我在 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/