列表页用插件搜索时间总结

原理:将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'});">

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值