1
我會將自定義列添加到表格用戶中。我正在使用symfony和fosuserbundle。在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);
新用戶將被添加到表中,但在$用戶價值setNonotification(1)不會被設置。 Symfony中沒有錯誤。
我的錯誤在哪裏?