我有我的用户实体设置,电子邮件(varchar)作为主键(id)我做了一个注册表,一切工作正常
问题是当我在数据库中提交表单时,电子邮件栏是空的
用户实体:
/**
* Utilisateur
*
* @ORM\Table(name="utilisateur", indexes={@ORM\Index(name="FK_utilisateur_niveau", columns={"niveau"})})
* @ORM\Entity
*/
class Utilisateur
{
/**
* @var string
*
* @ORM\Column(name="pseudo", type="string", length=150, nullable=false)
*/
private $pseudo;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=250, nullable=false)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=150, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
*/
private $email;
/**
* @var \EncheresBundle\Entity\Role
*
* @ORM\ManyToOne(targetEntity="EncheresBundle\Entity\Role")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="niveau", referencedColumnName="niveau")
* })
*/
private $niveau;
/**
* Set pseudo
*
* @param string $pseudo
*
* @return Utilisateur
*/
public function setPseudo($pseudo)
{
$this->pseudo = $pseudo;
return $this;
}
/**
* Get pseudo
*
* @return string
*/
public function getPseudo()
{
return $this->pseudo;
}
/**
* Set password
*
* @param string $password
*
* @return Utilisateur
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set email
*
* @param string $email
*
* @return Utilisateur
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Set niveau
*
* @param \EncheresBundle\Entity\Role $niveau
*
* @return Utilisateur
*/
public function setNiveau(\EncheresBundle\Entity\Role $niveau = null)
{
$this->niveau = $niveau;
return $this;
}
/**
* Get niveau
*
* @return \EncheresBundle\Entity\Role
*/
public function getNiveau()
{
return $this->niveau;
}
}以下是插入块:
if ($form->isSubmitted() && $form->isValid()) {
$obj->setEmail($form['email']->getData());
$obj->setPseudo($form['pseudo']->getData());
$obj->setPassword($form['password']->getData());
$obj->setNiveau($form['niveau']->getData());
$em = $this->getDoctrine()->getManager();
$em->persist($obj);
$em->flush();
$this->addFlash('notice', 'Inscription effectuee !');
return $this->redirectToRoute('login');
}我哪里错了?
发布于 2016-08-05 17:36:58
因此,经过长时间的搜索,我找到了解决方案,我编辑了文件user.orm.xml
<id name="email" type="string" column="email" length="150">
<generator strategy="IDENTITY"/>
</id>至
<id name="email" type="string" column="email" length="150">
</id>删除use实体并重新生成后:)
发布于 2016-08-05 07:15:05
将您的类更改为具有唯一Id是否足够简单?我在网上看了一下,我认为Doctrine Id需要是一个整数(您使用的是哪个数据库?)。
因此,您可以修改代码并添加ID,如下所示:
class Utilisateur
{
/**
* @ORM\Id
* @ORM\Column(name="util_id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $util_id;
...
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=150, nullable=false)
*/
private $email;
...我认为这将是一个快速的解决方案,并且会很好地工作。
https://stackoverflow.com/questions/38778567
复制相似问题