0

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

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

其实这是action方法:

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)));

提前致谢!

4

1 回答 1

1

该问题与Doctrine无关。答案在您收到的错误消息中。

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

于 2013-08-30T17:59:24.117 回答