mouse-tm/yii2-timeline-widget
渲染简单时间轴的控件
1.1.4
2021-12-09 07:47 UTC
Requires
- php: >=7.1.0
- yiisoft/yii2: ^2.0.13
This package is not auto-updated.
Last update: 2024-09-26 22:32:42 UTC
README
安装
安装此扩展的首选方式是通过 Composer。
运行以下命令之一
php composer.phar require --prefer-dist mice-tm/yii2-timeline-widget "*"
或者
"mice-tm/yii2-timeline-widget": "*"
将以下内容添加到您的 composer.json
文件的 require 部分中。
使用方法
时间轴控件期望在 items
参数中提供一个类似于 LogModel 的模型数组(micetm\timeline\LogModel)。其中,title
和 body
可以包含以 yii 宏格式({here-is-macros}
)表示的宏字符串。通过 eventIcons
参数,您可以扩展或重新分配动作的图标。
class LogModel extends Model { public $action; public $title, public $body; public $log_date; public $macros; public $_id; public function rules() { return [ [['action', 'title'], 'required'], [['action', 'title', 'body'], 'string'], ['log_date', 'integer'], ['macros', 'safe'] ]; } public function attributes() { return [ '_id', 'action', 'title', 'body', 'macros', 'log_date', ]; } public function attributeLabels() { return [ '_id' => '#', 'action' => 'Action', 'macros' => 'Macros', 'title' => 'Title', 'body' => 'Body', 'log_date' => 'Date', ]; } }
扩展安装后,只需在代码中简单使用它即可
<?php use micetm\timeline\Timeline; /** * @var $dataProvider \yii\data\ActiveDataProvider */ echo Timeline::widget([ 'items' => $dataProvider->getModels(), 'eventIcons' => [ 'update' => 'fa fa-pencil bg-orange', 'add' => 'fa fa-pencil bg-orange', 'create' => 'glyphicon glyphicon-star bg-green', ] ]); ?>