how to configure the ModelSearch so that the index only shows the records that are made during the day?
how to configure the ModelSearch so that the index only shows the records that are made during the day?
The provider for a grid accepts a criteria. You need to modify it adding extra “where”.
I am trying this way but I get error Invalid argument supplied for foreach()
$startdate = date('Y-m-d', mktime(0, 0, 0, date('d'), 1, date('Y')));
$dateend = date('Y-m-d', mktime(0, 0, 0, date('d') + 1, 1, date('Y')));
$query = Pagos::find()->where('>=', 'fecha', '$startdate')->andwhere('<', 'fecha', '$dateend ');
I save the dates on the form like a this
<?= $form->field($model, 'fecha')->textInput(['value'=>date("Y-m-d H-i-s"), 'readonly'=> true] )?>
where()
requires an array as Paramter. You provided 3 Strings instead.
Here a better approach:
$dateTime = new \DateTime();
$dateFormat = 'Y-m-d';
$from = $dateTime->format($dateFormat);
$till = $dateTime->modify('+1 day')->format($dateFormat);
$results = Pagos::find()->where([
'between','fecha',$from ,$till
])->all();
Thank you
Remove ->all() at the end of $query
and it worked
$dateTime = new \DateTime();
$dateFormat = 'Y-m-d';
$from = $dateTime->format($dateFormat);
$till = $dateTime->modify('+1 day')->format($dateFormat);
$results = Pagos::find()->where([
'between','fecha',$from ,$till
]);