实体:
class User
{
/**
* @var integer
*
* @ORM\Column(type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
...
但我尝试将IDENTITY更改为AUTO并且相同。
形式:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email',EmailType::class, array('label'=>'E-mail'))
->add('login',TextType::class, array('label'=>'Login'))
->add('password',PasswordType::class, array('label'=>'Hasło'))
->add('name',TextType::class, array('label'=>'Imię'))
->add('surname',TextType::class, array('label'=>'Nazwisko'))
->add('Zarejestruj',SubmitType::class, array('label'=>'Zarejestruj'));
}
控制器:
$user = new User();
$form=$this->createForm(Register::class, $user);
$form->handleRequest($request);
if ($form->isValid())
{
$data=$request->request->all();
$username=$data['register']['login'];
$password=$data['register']['password'];
$email=$data['register']['email'];
$name=$data['register']['name'];
$surname=$data['register']['surname'];
$user=new User();
$user->setLogin($username);
$user->setPassword($password);
$user->setEmail($email);
$user->setName($name);
$user->setSurname($surname);
$add=$this->getDoctrine()->getManager();
$add->persist($user);
$add->flush();
...
我仍有错误:
An exception occurred while executing 'INSERT INTO user (login, password, email, name, surname) VALUES (?, ?, ?, ?, ?)' with params ["test2", "test2", "Taylor", "David", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'surname' cannot be null
我在symofny 3.1.4中做到了并且它有效,但现在我使用symfony 3.1.5现在我遇到了这个问题......