0

I get this error when I'm trying to post a DateType to my database via a form.

My formType.php

   $builder
        ->add('date', DateType::class, array(
            'widget' => 'single_text',
        ))

My Entity

 /**
 * @ORM\Column(name="date", type="datetime", nullable=true)
 */
 private $date;

I really don't know where the type "string" comes from because I don't specify iy anywhere.

2
  • Most likely your date comes as a string representation from your form and you haven't transformed it into a "DateType" object yet. Commented May 2, 2018 at 9:25
  • Shouldnt the input field with type "date" do that for me? Commented May 2, 2018 at 9:28

1 Answer 1

2

Does your setter method looks like the following

/**
* Set date
*
* @param \DateTime $date
*
* @return EntityName
*/
public function setDate($date)
{
    $this->date = $date;
    return $this;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I overlooked the arguments in the set function. The setDate function has string $date. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.