1.时间搜索
页面:
[
'attribute' => 'start_time',
'filter' => \kartik\widgets\DatePicker::widget([
'name' => 'SearchModel[st_time]',
'value' => Yii::$app->request->get('SearchModel')['st_time'] ? Yii::$app->request->get('SearchModel')['st_time'] : '',
'language' => 'zh-CN',
'layout' => '{picker}{input}',
'pluginOptions' => [
'format' => 'yyyy-mm-dd',
'todayHighlight' => true,// 今日高亮
'autoclose' => true,// 选择后自动关闭
'todayBtn' => true,// 今日按钮显示
],
'options' => [
'class' => 'form-control no_bor',
]
]),
'value'=>function($model){
return date('Y-m-d H:i:s',$model->start_time);
},
'format' => 'raw',
],
控制器:
public function actionIndex()
{
$searchModel = new SearchModel([
'model' => $this->modelClass,
'scenario' => 'default',
'partialMatchAttributes' => ['promotion_name'], // 模糊查询
'defaultOrder' => [
'updated_at' => SORT_DESC
],
'pageSize' => $this->pageSize
]);
$dataProvider = $searchModel
->search(Yii::$app->request->queryParams);
$dataProvider->query
->andWhere(['>=', 'status', StatusEnum::DISABLED]);
$st_time = Yii::$app->request->get('SearchModel')['st_time'];
$st_time && $dataProvider->query->andFilterWhere(['between','start_time',strtotime($st_time),strtotime($st_time)+86399]);
$et_time = Yii::$app->request->get('SearchModel')['et_time'];
$et_time && $dataProvider->query->andFilterWhere(['between','end_time',strtotime($et_time),strtotime($et_time)+86399]);
return $this->render($this->action->id, [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}