R
R
Ruslan Ruslanov2019-05-08 09:06:26
Yii
Ruslan Ruslanov, 2019-05-08 09:06:26

Load() method not working in yii2?

I'm trying to attach `dosamigos/DatePicker`, but it doesn't work.
I pass get parameters to the search model:

$data_provider = $search_model->search(Yii::$app->request->queryParams);

the data array successfully arrives both in the controller and in the model.
SearchModel extends ModelName {
    //code
        public function rules {
            return [['created_at'], 'safe'];
        }

        public function search($params){        
    //code
            $this->load($params);
    //code
        }
    }

however, after $this->load in the search model, the created_at property is empty for some reason, although other parameters are written quite successfully and $params['created_at'] is also present.
What could be the reason?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
R
Ruslan Ruslanov, 2019-05-08
@dasauser

It turns out that it was necessary to explicitly specify the class name in the input name:

'filter' => DatePicker::widget([
                    'name' => 'ImagesSearch[created_at]', //было просто 'created_at'
                    'clientOptions' => [
                        'format' => 'dd-mm-yyyy'
                    ]
                ])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question