简体   繁体   中英

datetimepicker in Sonata Admin not working

How would I create a datetime field in the Sonata Admin Bundle which uses the sonata_type_datetime_picker? When I clicked submit, the Symfony Profiler will show error as show in the picture below. 错误

Here is my code:

EventAdmin.php

class EventAdmin extends Admin
    {
        // Fields to be shown on create/edit forms
        protected function configureFormFields(FormMapper $formMapper)
        {
            $formMapper
                ->add('eventDate', 'sonata_type_datetime_picker', array(
                    'label' => 'Event Date',
                    'format' => 'YYYY-MM-DD HH:mm:ss',
                    'dp_language' => 'en',
                    'dp_side_by_side'       => true,
                    'dp_use_current'        => false,
                    'datepicker_use_button' => false,
                ))  
            ;
        }
    }

Event.php

    /**
     * @ORM\Column(type="datetime")
     */
    protected $eventDate;

    /**
     * Set eventDate
     *
     * @param \DateTime $eventDate
     *
     * @return Event
     */
    public function setEventDate($eventDate)
    {
        $this->eventDate = $eventDate;

        return $this;
    }

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

I believe your only options for formatting is a combination of these letters:

'format'=>"YYYY-MM-D h:mm:ss a" //2015-01-19 8:05:00 AM

You can add or subtract each letter for different formats. For instance, YYYY-MMM-DD HH:mm will display as 2015-Jan-19 08:05

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM