fos创建用户Symfony

时间:2018-10-02 17:31:39

标签: php symfony fosuserbundle

所以我正在与fosuser合作! 我设法在班上添加了一些字段

<?php
namespace mynamespace;

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

class Person extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(name="about", type="string", length=255,nullable=true)
     */
    private $about;

    // Change the targetEntity path if you want to create the group

    /**
     * @ORM\ManyToMany(targetEntity="userBundle\Entity\Group")
     * @ORM\JoinTable(name="fos_user_user_group",
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
     * )
     */
    protected $groups;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

    /**
     * Get about
     *
     * @return String
     */
    public function getAbout()
    {
        return $this->about;
    }

    /**
     * Set about
     *
     * @param String $about
     * @return User
     */
    public function setAbout($about)
    {
        $this->about = $about;

        return $this;
    }
}

之后,我使用以下命令更新了数据库的架构

php bin/console doctrine:schema:update --force

问题是,当我尝试使用命令行创建fos:user时出现此错误

An exception occurred while executing 'INSERT INTO fos_user (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, passw
  ord_requested_at, roles, about) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

我不能手动在数据库中插入值,因为某些字段像密码一样被加密了

我该怎么做才能更新fos:user:create命令,以便我可以填写“关于”字段

谢谢

1 个答案:

答案 0 :(得分:2)

在构造中设置一个默认值,以便在插入数据库时​​没有空值:

public function __construct()
    {
        parent::__construct();
        $this->about = "default about value"; //<-- add this
        // your own logic
    }