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条回答 默认 最新

  • douping6871 2018-10-02 17:50
    关注

    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
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码