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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM