0

カスタム プロパティ (psptCode) を User エンティティに追加して、UserBundle を拡張しようとしています。これは私のユーザークラスです:

<?php

namespace AppBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use JMS\Serializer\Annotation as JMSSerializer;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Model\UserInterface;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 *
 * @UniqueEntity("email")
 * @UniqueEntity("username")
 * @UniqueEntity("psptCode")
 * @JMSSerializer\ExclusionPolicy("all")
 * @JMSSerializer\AccessorOrder("custom", custom = {"id", "emailCanonical", "account"})
 */
class User extends BaseUser implements UserInterface
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @JMSSerializer\Expose
     * @JMSSerializer\Type("string")
     */
    protected $id;

    /**
     * @var string The canonical representation of the email of the user.
     *
     * @JMSSerializer\Expose
     * @JMSSerializer\Type("string")
     * @JMSSerializer\SerializedName("email")
     * @JMSSerializer\Groups({"user_all", "user_summary"})
     */
    protected $emailCanonical;

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

    /**
     * @var Account The Pspt account related to this user, if any
     *
     * @ORM\OneToOne(targetEntity="Account")
     * @ORM\JoinColumn(name="pspt_code", referencedColumnName="cli_id", nullable=true)
     * @JMSSerializer\Expose
     * @JMSSerializer\Type("AppBundle\Entity\Account")
     * @JMSSerializer\Groups({"user_all"})
     */
    protected $account;

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @param $pspt_code
     *
     * Set the cli_id to retrieve the account, if any
     * @return User
     */
    public function setPsptCode($pspt_code)
    {
      $this->psptCode = $pspt_code;

      return $this;
    }

    /**
     * Get psptCode
     * @return string
     */
    public function getPsptCode()
    {
      return $this->psptCode;
    }
}

データベース スキーマを作成すると、カスタム プロパティが作成されますが、カスタム プロパティに値を保存しようとすると、データベースに保持されません。

$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setUsername('peter');
$user->setEmail('peter@test.com');
$user->setPlainPassword('testpass');
$user->setPsptCode('XXXXXXXXXX');
$this->userManager->updateUser($user);

ユーザーは次のように保存されます。

AppBundle\Entity\User {#4041
  #id: 1
  #emailCanonical: "peter@test.com"
  -psptCode: null
  #account: null
  #username: "peter"
  #usernameCanonical: "peter"
  #email: "peter@test.com"
  #enabled: true
  #salt: null
  #password: "$2y$15$OJ4ynZmpBaDYbK7N.d35m.FdcSHGpZG7Yemcwxrg4kHhKzIyP3XOO"
  #plainPassword: null
  #lastLogin: null
  #confirmationToken: null
  #passwordRequestedAt: null
  #groups: null
  #roles: []
}

そのため、ユーザーのカスタム プロパティを保存できません。助けてください!

4

0 に答える 0