kartik-v / yii2-date-range

A Date Range Picker for Bootstrap useful for reports and filtering.
http://demos.krajee.com/date-range
Other
93 stars 81 forks source link

startAttribute and endAttribute configuration ignored #70

Closed firefox747 closed 8 years ago

firefox747 commented 8 years ago

Hi, i am getting the following error Setting unknown property: <ModelNameHere>::startAttribute with startAttribute and endAttribute configured like this

'startAttribute' => 'fiscalYearBegin',
'endAttribute' => 'fiscalYearEnd',

I traced the error to lines 484 of the DateRangePicker.php:

protected function initRangeValue($type = '', $value = '')
    {
        $attr = $type . 'Attribute';
        if (!$this->$attr || empty($value)) {
            return;
        }
        if ($this->hasModel()) {
            $this->model->$attr = $value;
        } else {
            $opts = $type . 'InputOptions';
            $options = $this->$opts;
            $options['value'] = $value;
            $this->$opts = $options;
        }
    }

So. As far as i understand it $attr is either "startAttribute" or "endAttribute". Both are public properties within the DateRangePicker. But in line 491 $this->model->$attr = $value; the model is expected to have properties named exactly like that, ignoring the configuration and content of the widgets properties. My guess is it should read: $this->model->{$this->$attr} = $value; ... at least that works for me.

Cheers Kai

Rogork commented 8 years ago

Ran into the same problem and the suggested fix also worked for me, should be added to the main git.

kartik-v commented 8 years ago

Will provide a fix for this soon.