Как сделать фильтрации date для колонки created_at в gridview?

Пробовал 2 способа, это изменить параметры получаемы в get запросах. Но понял что они не изменяемые. Потом сделал новый для колонок переменную, минус в том, что когда фильтруешь, ничего не выводиться.
User модели
public $date_registration;
public function rules()
    {
        return [
            ....
            [['auth_date', 'date_registration'], 'safe'],
          ...
        ];
    }
public function attributeLabels()
    {
        return [
            ....
            'date_registration' => 'Дата регистрации'
        ];
    }


UserSearch
public $date_registration;
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            ...
            [['date_registration'], 'date', 'format' => 'php:Y-m-d']
        ];
    }
$query->andFilterWhere([
...
            'created_at' => $this->date_registration ? strtotime($this->date_registration) : null,
           ...
        ]);


GridView
<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ...
            [
                'attribute' => 'date_registration',
                'label' => 'Дата регистрации',
                'format' => 'datetime',
                'value' => function($date) {
                    return $date->created_at;
                },
                'filter' => Html::input('date', 'UsersSearch[date_registration]'),
            ],          
...
        ],
    ]); ?>
  • Вопрос задан
  • 55 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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