Doctrine不刷新null持久化实体对象

时间:2013-08-30 17:54:59

标签: php symfony doctrine entity

我正在尝试刷新一个持久的实体对象,但我收到此错误消息:

Fatal error: Call to a member function format() on a non-object in C:\xampp\htdocs\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\DateType.php on line 44

实际上这是行动方法:

public function processRegisterFormAction()
{

    $data = filter_var_array($_POST['form'], FILTER_SANITIZE_STRING);
    extract($data);

    $customer  = new Customer();

    $dob = explode('/', $date_of_birth);
    $date_of_birth = $dob[2] . '-' . $dob[1] . '-' . $dob[0];

    $datetime = date('Y-m-d H:i:s');

    $customer->setEmail($email);
    $customer->setPassword($password);
    $customer->setName($name);
    $customer->setGender($gender);
    $customer->setDateOfBirth($date_of_birth);
    $customer->setZipcode($zipcode);
    $customer->setState($state);
    $customer->setCity($city);
    $customer->setDistrict($district);
    $customer->setAddress($address);
    $customer->setStreetNumber($street_number);
    $customer->setCompanyName($company_name);
    $customer->setCreated( $datetime);
    $customer->setLastModified($datetime);

    $em = $this->getDoctrine()->getManager();
    $em->persist($customer);
    $em->flush();

    return new Response('Created Customer ' . $customer->getId() );

}

在我的实体中,我已声明$ dateOfBirth,$ created,$ lastModified为" String"因为我认为这是与日期时间有关的东西,但是,没有!

我倾销了$ em-> persist($ customer)它返回NULL

die(var_dump($em->persist($customer)));

提前致谢!

1 个答案:

答案 0 :(得分:1)

问题与Doctrine无关。答案在你得到的错误信息中。

您正在对不是DateTime对象的变量调用format()。在调用format()帮助程序之前,请确保您的变量是DateTime的实例。