我将自定义列填入表用户。我正在使用symfony和fosuserbundle。
这是我的自定义user.php
namespace MBS\UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var boolean
*/
private $nonotification;
/**
* Set nonotification
*
* @param boolean $nonotification
* @return User
*/
public function setNonotification($nonotification)
{
$this->nonotification = $nonotification;
return $this;
}
/**
* Get nonotification
*
* @return boolean
*/
public function getNonotification()
{
return $this->nonotification;
}
/**
* @ORM\ManyToMany(targetEntity="MBS\UserBundle\Entity\Group")
* @ORM\JoinTable(name="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();
}
}
在我的控制器中我使用它:
$userManager = $this->get('fos_user.user_manager');
$user = $userManager->createUser();
$user->setUsername( $username );
$user->setEmail( $email );
$user->setPlainPassword( $password );
$user->setEnabled(true);
$user->setNonotification( 1 );
$userManager->updateUser($user);
新用户将被添加到表中,但不会设置$ user-setNonotification(1)上的值。我没有在Symfony中出错。
我的错误在哪里?
答案 0 :(得分:4)
您忘记声明nonotification
字段
/**
* @var boolean
* @ORM\Column(type="boolean")
*/
private $nonotification;