How to setup the search model in yii2?

Hello, tell me how to do filtering data in a GridView.

This DatePicker https://github.com/2amigos/yii2-date-picker-widget
In GridView set up all the way:
[
 'attribute' => 'created_at',
 'format' => 'datetime',
 'value' => 'created_at',
 'filter' => DatePicker::widget([
 'model' => $searchModel,
 'attribute' => 'created_at',
 'language' => 'EN',
 'clientOptions' => [
 'autoclose' => true,
 'format' => 'dd.mm.yyyy'
],
]),
],

The date works, the date in the model is out of format d.m.Y

Date in database is stored in int

Know what you want to change, how could not understand:
$query->andFilterWhere([
 'id' => $this->id,
 'status' => $this->status,
 'created_at' => $this->created_at,
 'updated_at' => $this->updated_at,
]);
June 14th 19 at 20:07
1 answer
June 14th 19 at 20:09
Solution
Good evening.
Try the following method.
In search model, add the properties, validation rules and criteria in a query
public $date_from;
public $date_to;

[['date_from', 'date_to'], 'date', 'format' => 'php:Y-m-d']

$query->andFilterWhere(['>=', 'created_at', $this->date_from ? strtotime($this->date_from . '00:00:00') : null])
 ->andFilterWhere(['<=', 'created_at', $this->date_to ? strtotime($this->date_to . '23:59:59') : null ]);

A search between dates.
Modify to fit your needs.
Did so, but apparently made a mistake.

Eventually did this:

[['created_at', 'updated_at'], 'integer' , 'when' => function($model, $attribute){
 return !(is_numeric(strtotime($model->$attribute)));
}]

$query->andFilterWhere([
'and',
 ['>=', 'created_at', ($this->created_at) ? strtotime($this->created_at . '00:00:00') : null],
 ['<=', 'created_at', ($this->created_at) ? strtotime($this->created_at . '23:59:59') : null],
]);
- Baylee43 commented on June 14th 19 at 20:12

Find more questions by tags MySQLPHPYii