Jalali date & time is an extension for yii2.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mohammad-mahdy/yii2-jdate "*"
or add
"mohammad-mahdy/yii2-jdate": "*"
to the require section of your composer.json
file.
DateTime
Once the extension is installed, add it as a component :
'jdate' => [
'class' => 'jDate\DateTime'
]
Now you can use in your project:
Yii::$app->jdate->date('Y-m-d');
You can access dates and times as variable :
Yii::$app->jdate->Y;
DatePicker
It is a widget to make a input, box to giver jalali date from user.
A basic usage:
<?= jDate\DatePicker::widget([
'name' => 'datepicker'
]) ?>
If you want set default date set value
:
<?= jDate\DatePicker::widget([
'name' => 'datepicker', 'value' => '1394/01/01'
]) ?>
Using a model
:
<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date'
]) ?>
Use in active form
:
<?= $form->field($model, 'fieldname')->widget(jDate\DatePicker::className()) ?>
ClientOptions
Add these to
ClientOptions
var.
[
'cellHeight' => 13,
'cellWidth' => 13
]
[
'fontSize' => 25
]
[
'persianNumbers' => false
]
[
'formatDate' => 'DD-NM-YYYY hh:m'
]
Theme
Now date picker have 2 theme default
and dark
.
For set theme set theme
var.
<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date', 'theme' => 'dark'
]) ?>
Events
NOTE : If you want rewriting onSelect event and using
active form
addoptions[id]
and add$('#your id').trigger('change');
to your event function.
onHide
Event:<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date',
'ClientOptions' => [
'onHide' => 'function(){alert("Datepicker is now hidden!")}'
]
]) ?>
onSelect
Event:<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date',
'ClientOptions' => [
'onSelect' => 'function(){alert("Date selected!")}'
]
]) ?>
onShow
Event:<?= jDate\DatePicker::widget([
'model' => $model, 'attribute' => 'date',
'ClientOptions' => [
'onShow' => 'function(){alert("Hello!")}'
]
]) ?>