原理:将laydate插建文件下载后,不要动目录结构,需要使用的地方直接引用laydate.js文件
1.index.php中
[ 'attribute' => 'add_time', 'format' => ['date'], 'filter' => Html::activeInput('text', $searchModel, 'create_start_at', [ 'class' => 'form-control layer-date', 'placeholder' => '', 'onclick' => "laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'});" ]) . Html::activeInput('text', $searchModel, 'create_end_at', [ 'class' => 'form-control layer-date', 'placeholder' => '', 'onclick' => "laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" ]), ],2.models/ArticleSearch.php中
public $create_start_at; public $create_end_at; public $update_start_at; public $update_end_at;
[['create_start_at', 'create_end_at', 'update_start_at', 'update_end_at'], 'string'],//时间搜索加的
//时间搜索测试开始 $create_start_at_unixtimestamp = $create_end_at_unixtimestamp = $update_start_at_unixtimestamp = $update_end_at_unixtimestamp = ''; if ($this->create_start_at != '') { $create_start_at_unixtimestamp = strtotime($this->create_start_at); } if ($this->create_end_at != '') { $create_end_at_unixtimestamp = strtotime($this->create_end_at); } if ($this->update_start_at != '') { $update_start_at_unixtimestamp = strtotime($this->update_start_at); } if ($this->update_end_at != '') { $update_end_at_unixtimestamp = strtotime($this->update_end_at); } if ($create_start_at_unixtimestamp != '' && $create_end_at_unixtimestamp == '') { $query->andFilterWhere(['>', 'add_time', $create_start_at_unixtimestamp]); } elseif ($create_start_at_unixtimestamp == '' && $create_end_at_unixtimestamp != '') { $query->andFilterWhere(['<', 'add_time', $create_end_at_unixtimestamp]); } else { $query->andFilterWhere([ 'between', 'add_time', $create_start_at_unixtimestamp, $create_end_at_unixtimestamp ]); } if ($update_start_at_unixtimestamp != '' && $update_end_at_unixtimestamp == '') { $query->andFilterWhere(['>', 'update_time', $update_start_at_unixtimestamp]); } elseif ($update_start_at_unixtimestamp == '' && $update_end_at_unixtimestamp != '') { $query->andFilterWhere(['<', 'update_time', $update_start_at_unixtimestamp]); } else { $query->andFilterWhere([ 'between', 'update_time', $update_start_at_unixtimestamp, $update_end_at_unixtimestamp ]); } 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
其他项目里,将laydate放到了web中
backend-》assets-》AppAsset中(这样是找到根目录下web)
public $js = [ 'laydate/laydate.js', ];原生的写法:
<input id="startTime" name="startTime" class="form-control layer-date" type="text" value="<?php echo $startTime;?>" οnclick="laydate({istime: true, format: 'YYYY-MM-DD'});">