zoukankan      html  css  js  c++  java
  • fastadmin 后台管理 时间戳字段使用

    数据库样式 int 11

    后台add.html:

    <div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('Lotterytime')}:</label>
    <div class="col-xs-12 col-sm-8">
    <input id="c-lotterytime" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[lotterytime]" type="text" value="{:date('Y-m-d H:i:s')}">
    </div>
    </div>

    edit.html:
    <div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('Lotterytime')}:</label>
    <div class="col-xs-12 col-sm-8">
    <input id="c-lotterytime" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[lotterytime]" type="text" value="{$row.lotterytime|datetime}">
    </div>
    </div>

    有时会发现这种方法提交会导致数据库中只存了4位的年份值,因为添加编辑提交的是:Y-m-d H:i:s样式,系统只能检测到第一个年份,需要后台controller对应的model转换一下

    转换代码:
    // 追加属性
    protected $append = [
    'lotterytime_text'
    ];

    public function getLotterytimeTextAttr($value, $data)
    {
    $value = $value ? $value : (isset($data['lotterytime']) ? $data['lotterytime'] : '');
    return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    protected function setLotterytimeAttr($value)
    {
    return $value && !is_numeric($value) ? strtotime($value) : $value;
    }
  • 相关阅读:
    二进制位运算
    Leetcode 373. Find K Pairs with Smallest Sums
    priority_queue的用法
    Leetcode 110. Balanced Binary Tree
    Leetcode 104. Maximum Depth of Binary Tree
    Leetcode 111. Minimum Depth of Binary Tree
    Leetcode 64. Minimum Path Sum
    Leetcode 63. Unique Paths II
    经典的递归练习
    案例:java中的基本排序
  • 原文地址:https://www.cnblogs.com/daochong/p/10613351.html
Copyright © 2011-2022 走看看