Az Emna
Az Emna

Reputation: 535

fos create user 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

Upvotes: 1

Views: 452

Answers (1)

zizoujab
zizoujab

Reputation: 7800

In your construct set a default value so that you dont have an empty value when inserting in database:

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

Upvotes: 2

Related Questions