doufangyan6862 2012-08-21 15:59
浏览 41
已采纳

Doctrine不会映射FOSUserBundle User类中的字段

I am using Symfony 2.1 RC1 and the FOSUserbundle on a Windows server running PHP 5.3.13.

I have followed the instructions here but Doctrine doesn't create fields in the database for the properties inherited from the base FOS User class (only the fields from my class).

Trying to login using the FOS login form produces the error:

Unrecognized field: usernameCanonical

I have the following Doctrine configuration:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

And the FOSUserBundle config looks like:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: SP\PickList\UserBundle\Entity\User

My User entity:

namespace SP\PickList\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Document\User as BaseUser;

/**
 * SP\PickList\UserBundle\Entity\User
 *
 * @ORM\Table(name="fos_user")
 * @ORM\Entity
 */
class User extends BaseUser
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
}

Thanks for any help,

James Bench

  • 写回答

4条回答 默认 最新

  • dtch60248 2012-08-21 19:55
    关注

    It seems you are mixing instructions for ORM and ODM, if you use Doctrine ORM as per your config, your User class must extend FOS\UserBundle\Entity\User, try to change the use statement as

    use FOS\UserBundle\Entity\User as BaseUser;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应