postgresqlsymfonydatedoctrine-ormsonata-admin

Simple date with Sonata Admin Bundle


I have a form with Sonata Admin Bundle with a date, to set the birthday of the user we want to add. Here goes MemberAdmin.php :

/**
 * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
 *
 * @return void
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->with('General')
            ->add('username')
            ->add('name')
            ->add('surname')
            ->add('birthdate', 'birthday', array('format' => 'yyyy-MM-dd'))
            // ...
}

And my problem is when I send the form, I obtain Error: Call to a member function format() on a non-object ... But if I do print_r($birthdate) in the Entity class it shows me the DateTime object ...

Here are the interesting Entity parts:

/**
 * @var date
 *
 * @ORM\Column(name="birthdate", type="date", nullable=true, options={"default" = "1990-01-01 00:00:00"})
 * @Assert\DateTime()
 */
private $birthdate;


/**
 * Set birthdate
 *
 * @param \DateTime $birthdate
 * @return Membre
 */
public function setBirthdate($birthdate)
{
    $this->birthdate = $birthdate;

    return $this;
}

/**
 * Get birthdate
 *
 * @return \DateTime 
 */
public function getBirthdate()
{
    return $this->birthdate;
}

My problem, currently, is that I don't know what I should do, I just want the date, no time, no anything else, i don't know if the column should be date (I work with PostgreSQL). What should I use for the types of my variables, I feel lost here, no simple Date possible ??

I tried to figure out from where it could come, but when I change too much I end up with: This form should not contain extra fields directly in the form, or even Incorrect value, but the field is a valid date ...

Thanks for your help !!


Solution

  • Edit

    As @rande said, modifying vendors files is not the way to go, it provided an easy temp workaround for a local private app. As it is not dedicated to stay like that, I took care of the issue once I had more time. Sorry for the delay to come back to you guys.

    I played around, tried with multiple setups, it took me time to figure it out, but I finally came to the conclusion that the issue... was caused by another date, that I was generating wrong in the constructor one line above.

    Also, thanks to all of you, that guided me on the right path!