Hi there,
I’m trying to filter my rest api data by a datetime value using operator < and by using the ActiveDataFilter.
I want to achieve something like this
/index.php?r=somecontroller%2Findex&filter[timestamp]<2020-12-21%2000%3A31%3A44
Filtering works fine when I try to filter with equal (=) operation, but when I use operator < the datetime value is not being parsed correctly.
Model is implemented like this:
class SomeModel extends Model
{
public $timestamp;
public function rules()
{
return [
['timestamp', 'datetime', 'format' => 'php:Y-m-d H:i:s'],
];
}
}
and data provider is implemented like:
public function indexDataProvider()
{
$model = new $this->modelClass;
$query = $model::find();
$filter = new ActiveDataFilter([
'searchModel' => 'models\SomeModel'
]);
$filterCondition = null;
if ($filter->load(\Yii::$app->request->get())){
$filterCondition = $filter->build();
}
if($filterCondition === null || $filterCondition === false || sizeof($filterCondition)===0)
throw new \yii\web\ForbiddenHttpException();
if ($filterCondition !== null) {
$query->andWhere($filterCondition);
}
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 4,
],
]);
return $dataProvider;
}
Any directions here are much appreciated.
Thank you