在Session中存储用户对象

时间:2016-09-26 13:51:36

标签: symfony session

我有一个User实体。一个用户可以购买产品。在表单验证之后,我想在$session中存储用户数据(ID,名称,邮件,密码,地址......),并且只有在成功付款后才从会话中检索此数据并将其存储到数据库。

这就是我正在做的事情:(如果来自有效)

        $session = new Session();
        $serialized_user = serialize($user);
        $session->set('myuser', ($serialized_user));

然后,在付款检查后:

        $test = ($this->get('session')->get('myuser'));
        $test_unserialized = unserialize($test);

        $em = $this->getDoctrine()->getManager();
        $em->persist($test_unserialized);
        $em->flush();
        return $this->render('UserBundle:Account:buyedOk.php');

我得到的是这个错误:

An exception occurred while executing 'INSERT INTO user (user, passw, email, is_active, is_locked, date_expire, date_registration, last_visit, name, surname, address, zipcode, city, province, country, vat, tel, fax, contact_name, contact_role, contact_email, contact_tel, email_hex, email_confirmed, validated,id_currency) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["March", "$2y$13$hTBP0ANwRlwgcfX19OtsTubn6ctI64lz5GVQ3JF3nZtD0GDPK8rTC", null, 0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null

建议?

0 个答案:

没有答案