dongqiao1964
2018-10-02 17:31
浏览 53
已采纳

fos创建用户Symfony

So I m working with fosuser ! I have managed to add some fields in my class

<?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;
    }
}

After that, I updated the schema of my database using the following command

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

The problem is when I try to create a fos:user with the command line I get this error

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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

And I cant insert the value on the database manually because some fields are encrypted like password

what can i do to update fos:user:create command so that I can fill the "about" field

Thank you

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新