หลักคำสอนไม่ล้างวัตถุเอนทิตีที่คงอยู่เป็นโมฆะ

ฉันกำลังพยายามล้างวัตถุเอนทิตีที่ Persited แต่ฉันได้รับข้อความแสดงข้อผิดพลาดนี้:

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" เพราะฉันคิดว่ามันเป็นเรื่องที่เกี่ยวข้องกับ datetime แต่ไม่!

และฉันทิ้ง $em->persist($customer) มันคืนค่า NULL

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

ขอบคุณล่วงหน้า!


person Gilberto Albino    schedule 30.08.2013    source แหล่งที่มา


คำตอบ (1)


ปัญหาไม่เกี่ยวข้องกับ Doctrine คำตอบอยู่ในข้อความแสดงข้อผิดพลาดที่คุณได้รับ

คุณกำลังเรียก format() บนตัวแปรที่ไม่ใช่ออบเจ็กต์ DateTime ตรวจสอบให้แน่ใจว่าตัวแปรของคุณเป็นอินสแตนซ์ของ DateTime ก่อนที่จะเรียก format() helper

person Ahmed Siouani    schedule 30.08.2013
comment
ไม่! ฉันไม่ได้ใช้มันทุกที่! - person Gilberto Albino; 30.08.2013
comment
จากนั้นคุณจะต้องดัมพ์แอตทริบิวต์เอนทิตีที่เหมือนวันที่และเวลาของคุณ และตรวจสอบให้แน่ใจว่าคุณส่งวัตถุ/สตริงที่ถูกต้องโดยใช้รูปแบบที่ถูกต้อง เนื่องจาก format() กำลังเรียกที่ไหนสักแห่งในตัวแปรซึ่งต้องเป็นอินสแตนซ์ของ DateTime แต่ไม่ใช่ อัปเดตคำถามของคุณด้วยคำจำกัดความแอตทริบิวต์ dateOfBirth สร้าง และแก้ไขล่าสุด - person Ahmed Siouani; 30.08.2013