paolo@bimodesign.com | +34 608 61 64 10

Framework

        

Doctrine - DateTimePicker

If you to create in Zend 2 using Doctrine, a calendar like this

doctrine jQuery Data Picker
You need to structure the code in this way.
1. Datatimepicker jQuery library
First all download the js and css files from my site (.zip) and then install it into your application.

2. Add your jQuery code in this way (I have two different input data values)

$(document).ready(function () {
    
    $('.form_datetime_conf').datetimepicker({
        language:  'fr',
        weekStart: 0,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        format:'yyyy-mm-dd hh:ii:ss'
    });
    
    $('.form_datetime_pause').datetimepicker({
        language:  'fr',
        weekStart: 0,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        format:'yyyy-mm-dd hh:ii:ss'        
    });
    
});

Note: There are several parameters to configure, but the more important (for me) are:
- language: get the own jQuery language file version (into local/)
- format: to save the data by doctrine into the TIMESTAMP type data mysql

3. Manage data by Doctrine
To select and show the data into the form, I used this code in my controller:


    if ($this->getRequest()->isPost()) {
        ... code ...
        ... code ...
    }

    $dateConfigurationObj = $site->getContStateDateConfiguration();
    $datePauseObj = $site->getContStateDatePause();

    if ($dateConfigurationObj instanceof \DateTime) {
        $dataConfigurationFormat = $dateConfigurationObj->format('Y-m-d H:i:s');
    } else {
        $dataConfigurationFormat = "";
    }

    if ($datePauseObj instanceof \DateTime) {
        $dataPauseFormat = $datePauseObj->format('Y-m-d H:i:s');
    } else {
        $dataPauseFormat = "";
    }    

Note that the date has the same format of the custum jQuery configuration. And that I need to instance the DateTime
To modify the values date into the database, the code is

    public function updateState($id,$params) {
        $contest = new $this->entity;

        $contest = $this->find($id);
        $contest->setContState($params['cont_state']); 
        $contest->setContStateDateConfiguration(new \DateTime($params['cont_state_date_configuration']));  
        $contest->setContStateDatePause(new \DateTime($params['cont_state_date_pause']));  
        
        $this->em->persist($contest);
        $this->em->flush();

        return true;
    }    

Notice that also in this case I need to istance Datetime before to persist and flush.