@skajtersen

Как связать значения из DateRangePicker c переменными модели?

Имеется модель
class PlotCreation extends \yii\base\Model
{

    public $date_from;
    public $date_to;
...
}


В представлении есть виджет kartik\daterange\DateRangePicker
echo DateRangePicker::widget([
        'name' => 'date_range',
        'value' => '2017-05-02 01:00:00 PM - 2017-05-03 01:00:00 PM',
        'convertFormat' => true,
        'pluginOptions' => [
            'timePicker' => true,
            'timePickerIncrement' => 10,
            'locale' => ['format' => 'Y-m-d h:i:s']
        ]
    ]);


Подскажите, как что написать в контроллере, чтобы связать выбранные конечное и начальное значения с переменными $date_to и $date_from.
И можно ли в самом виджете добавить выбор таймзоны?
  • Вопрос задан
  • 502 просмотра
Решения вопроса 1
@B_bird
В документации написано:
startAttribute: string, the attribute name which you can set optionally to track changes to the range start value. One of the following actions will be taken when this is set:

If using with model, an active hidden input will be automatically generated using this as an attribute name for the start value of the range.

endAttribute: string, the attribute name which you can set optionally to track changes to the range end value. One of the following actions will be taken when this is set:

If using with model, an active hidden input will be automatically generated using this as an attribute name for the end value of the range.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
webinar
@webinar Куратор тега Yii
Учим yii: https://youtu.be/-WRMlGHLgRg
Пример из доков:
$model->datetime_start = '2016-02-11';
$model->datetime_end = '2016-03-15';
echo '<div class="input-group drp-container">';
echo DateRangePicker::widget([
    'model'=>$model,
    'attribute' => 'kvdate1',
    'useWithAddon'=>true,
    'convertFormat'=>true,
    'startAttribute' => 'datetime_start',
    'endAttribute' => 'datetime_end',
    'pluginOptions'=>[
        'locale'=>['format' => 'Y-m-d'],
    ]
]) . $addon;
echo '</div>';
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы