yii2使用时间插件
最近在学习yii2 框架,发现框架很强大,而且结合了时下许多新的技术在里面。
简单记录一下yii2-date-picker插件的使用方法:
首先先了解一下github中的相关资源:https://github.com/2amigos/yii2-date-picker-widget
其次:在自己的项目中利用上面链接中的相关方法下载此资源,命令为:
php composer.phar require “2amigos/yii2-date-picker-widget” “*”
最后,在视图文件中使用下面的代码:
use dosamigosdatepickerDatePicker;
例子中提供了两种方法:
1> 使用widget方式
<?= DatePicker::widget([
"model" => $model,
"attribute" => "date",
"template" => "{addon}{input}",
"clientOptions" => [
"autoclose" => true,
"format" => "dd-M-yyyy"
]
]);?>
2> ActiveForm方式
<?= $form->field($model, "date")->widget(
DatePicker::className(), [
// inline too, not bad
"inline" => true,
// modify template for custom rendering
"template" => "<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>",
"clientOptions" => [
"autoclose" => true,
"format" => "dd-M-yyyy"
],
"options"=>[
$model->date = date("Y-m-d H:i:s"),//格式化初始时间
]
]);?>
在model文件里面找到对应的字段,更改rule方法,格式化时间成为时间戳
["paytime" , "filter", "filter" => function(){
return strtotime($this->paytime);
}],
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。