Requirements
Symfony 2.8.* or 3.0+
PHP 5.6+ or 7.0+, (*1)
DatetimepickerBundle
This bundle implements the Bootstrap DateTime Picker in a Form Type for Symfony 2.*. The bundle structure is inspired by GenemuFormBundle., (*2)
Demo : http://www.malot.fr/bootstrap-datetimepicker/demo.php, (*3)
Please feel free to contribute, to fork, to send merge request and to create ticket., (*4)
Installation
Step 1: Install DatetimepickerBundle
Run command:, (*5)
composer require imiskuf/datetimepicker-bundle
Step 2: Enable the bundle
``` php
<?php
// app/AppKernel.php, (*6)
public function registerBundles()
{
$bundles = array(
// ...
new SC\DatetimepickerBundle\SCDatetimepickerBundle(),
);
}, (*7)
``` yml
# app/config/config.yml
sc_datetimepicker:
picker: ~
Step 3: Initialize assets
``` bash
$ php app/console assets:install web/, (*8)
## Usages
``` php
<?php
// ...
public function buildForm(FormBuilder $builder, array $options)
{
$builder
// defaut options
->add('createdAt', 'collot_datetime')
// full options
->add('updatedAt', 'collot_datetime', array( 'pickerOptions' =>
array('format' => 'mm/dd/yyyy',
'weekStart' => 0,
'startDate' => date('m/d/Y'), //example
'endDate' => '01/01/3000', //example
'daysOfWeekDisabled' => '0,6', //example
'autoclose' => false,
'startView' => 'month',
'minView' => 'hour',
'maxView' => 'decade',
'todayBtn' => false,
'todayHighlight' => false,
'keyboardNavigation' => true,
'language' => 'en',
'forceParse' => true,
'minuteStep' => 5,
'pickerReferer ' => 'default', //deprecated
'pickerPosition' => 'bottom-right',
'viewSelect' => 'hour',
'showMeridian' => false,
'initialDate' => date('m/d/Y', 1577836800), //example
))) ;
}
Add form_javascript and form_stylesheet, (*9)
The principle is to separate the javascript, stylesheet and html.
This allows better integration of web pages., (*10)
Example:
``` twig
{% block stylesheets %}
, (*11)
{{ form_stylesheet(form) }}
{% endblock %}, (*12)
{% block javascripts %}
, (*13)
{{ form_javascript(form) }}
{% endblock %}, (*14)
{% block body %}, (*15)
{% endblock %}
```, (*16)
Documentation
The documentation of the datetime picker is here : http://www.malot.fr/bootstrap-datetimepicker/#options, (*17)
Notes
The date format from php 'pickerOptions' => array('format'=>'dd MM yyyy - HH:ii p')
is used to set automatically the date format of Symfony in order to make compatible Symfony and JavaScript output.
But there are some problems for example with php MM
which display "décembre" in PHP intl translation and "Decembre" in Bootstrap translation. That is why I edited js/locales/bootstrap-datetimepicker.fr.js, (*18)